#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 */
float fabsf(float const);
float sqrtf(float);
void shallow2dv_speed(float *restrict cxy, const float *restrict h,
                      const float *restrict hu, const float *restrict hv,
                      float g, int ncell) {
  float cx = cxy[0];
  float cy = cxy[1];
  for (int i = 0; i < ncell; ++i) {
    float hi = h[i];
    float inv_hi = 1.0f / h[i];
    float root_gh = sqrtf(g * hi);
    float cxi = fabsf(hu[i] * inv_hi) + root_gh;
    float cyi = fabsf(hv[i] * inv_hi) + root_gh;
    if (cx < cxi)
      cx = cxi;
    if (cy < cyi)
      cy = cyi;
  }
  cxy[0] = cx;
  cxy[1] = cy;
}


x86 assembly (clang, -O0):
<shallow2dv_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movss  %xmm0,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    123a <shallow2dv_speed+0x12a>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  0xe8f(%rip),%xmm0
divss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x24(%rbp),%xmm0
mulss  -0x38(%rbp),%xmm0
call   1030 <sqrtf@plt>
movss  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mulss  -0x3c(%rbp),%xmm0
movaps 0xe48(%rip),%xmm1
pand   %xmm1,%xmm0
addss  -0x40(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mulss  -0x3c(%rbp),%xmm0
movaps 0xe21(%rip),%xmm1
pand   %xmm1,%xmm0
addss  -0x40(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x2c(%rbp),%xmm1
movss  -0x44(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    120a <shallow2dv_speed+0xfa>
movss  -0x44(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x30(%rbp),%xmm1
movss  -0x48(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1227 <shallow2dv_speed+0x117>
movss  -0x48(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
jmp    122c <shallow2dv_speed+0x11c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1153 <shallow2dv_speed+0x43>
movss  -0x2c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shallow2dv_speed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
movsd  (%rdi),%xmm5
test   %r8d,%r8d
jle    11e4 <shallow2dv_speed+0xd4>
movaps %xmm0,%xmm4
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %r8d,%ebx
xor    %ebp,%ebp
movss  0xeb9(%rip),%xmm6
xorps  %xmm8,%xmm8
movaps 0xebe(%rip),%xmm7
movss  %xmm0,0x8(%rsp)
jmp    11ca <shallow2dv_speed+0xba>
nopw   0x0(%rax,%rax,1)
movaps %xmm5,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
call   1030 <sqrtf@plt>
movss  0xc(%rsp),%xmm2
movaps 0xe93(%rip),%xmm7
xorps  %xmm8,%xmm8
movss  0xe77(%rip),%xmm6
movaps 0x10(%rsp),%xmm5
movss  0x8(%rsp),%xmm4
movaps %xmm6,%xmm1
divss  %xmm2,%xmm1
shufps $0x0,%xmm1,%xmm1
movss  (%r15,%rbp,4),%xmm2
movss  (%r12,%rbp,4),%xmm3
unpcklps %xmm2,%xmm3
mulps  %xmm1,%xmm3
andps  %xmm7,%xmm3
shufps $0x0,%xmm0,%xmm0
addps  %xmm3,%xmm0
maxps  %xmm5,%xmm0
add    $0x1,%rbp
movaps %xmm0,%xmm5
cmp    %rbp,%rbx
je     11e7 <shallow2dv_speed+0xd7>
movss  0x0(%r13,%rbp,4),%xmm2
movaps %xmm2,%xmm0
mulss  %xmm4,%xmm0
ucomiss %xmm8,%xmm0
jb     1160 <shallow2dv_speed+0x50>
sqrtss %xmm0,%xmm0
jmp    1194 <shallow2dv_speed+0x84>
movaps %xmm5,%xmm0
movss  %xmm0,(%r14)
shufps $0x55,%xmm0,%xmm0
movss  %xmm0,0x4(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @shallow2dv_speed(float* noalias %0, float* noalias %1, float* noalias %2, float* noalias %3, float %4, i32 %5) {
%7 = alloca float*
%8 = alloca float*
%9 = alloca float*
%10 = alloca float*
%11 = alloca float
%12 = alloca i32
%13 = alloca float
%14 = alloca float
%15 = alloca i32
%16 = alloca float
%17 = alloca float
%18 = alloca float
%19 = alloca float
%20 = alloca float
store float* %0, float** %7
store float* %1, float** %8
store float* %2, float** %9
store float* %3, float** %10
store float %4, float* %11
store i32 %5, i32* %12
%21 = load float*, float** %7
%22 = getelementptr inbounds float, float* %21, i64 0
%23 = load float, float* %22
store float %23, float* %13
%24 = load float*, float** %7
%25 = getelementptr inbounds float, float* %24, i64 1
%26 = load float, float* %25
store float %26, float* %14
store i32 0, i32* %15
br label %27
27: ; preds = %79, %6
%28 = load i32, i32* %15
%29 = load i32, i32* %12
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %82
31: ; preds = %27
%32 = load float*, float** %8
%33 = load i32, i32* %15
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds float, float* %32, i64 %34
%36 = load float, float* %35
store float %36, float* %16
%37 = load float*, float** %8
%38 = load i32, i32* %15
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds float, float* %37, i64 %39
%41 = load float, float* %40
%42 = fdiv float 1.000000e+00, %41
store float %42, float* %17
%43 = load float, float* %11
%44 = load float, float* %16
%45 = fmul float %43, %44
%46 = call float @sqrtf(float %45)
store float %46, float* %18
%47 = load float*, float** %9
%48 = load i32, i32* %15
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds float, float* %47, i64 %49
%51 = load float, float* %50
%52 = load float, float* %17
%53 = fmul float %51, %52
%54 = call float @llvm.fabs.f32(float %53)
%55 = load float, float* %18
%56 = fadd float %54, %55
store float %56, float* %19
%57 = load float*, float** %10
%58 = load i32, i32* %15
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds float, float* %57, i64 %59
%61 = load float, float* %60
%62 = load float, float* %17
%63 = fmul float %61, %62
%64 = call float @llvm.fabs.f32(float %63)
%65 = load float, float* %18
%66 = fadd float %64, %65
store float %66, float* %20
%67 = load float, float* %13
%68 = load float, float* %19
%69 = fcmp olt float %67, %68
br i1 %69, label %70, label %72
70: ; preds = %31
%71 = load float, float* %19
store float %71, float* %13
br label %72
72: ; preds = %70, %31
%73 = load float, float* %14
%74 = load float, float* %20
%75 = fcmp olt float %73, %74
br i1 %75, label %76, label %78
76: ; preds = %72
%77 = load float, float* %20
store float %77, float* %14
br label %78
78: ; preds = %76, %72
br label %79
79: ; preds = %78
%80 = load i32, i32* %15
%81 = add nsw i32 %80, 1
store i32 %81, i32* %15
br label %27
82: ; preds = %27
%83 = load float, float* %13
%84 = load float*, float** %7
%85 = getelementptr inbounds float, float* %84, i64 0
store float %83, float* %85
%86 = load float, float* %14
%87 = load float*, float** %7
%88 = getelementptr inbounds float, float* %87, i64 1
store float %86, float* %88
ret void
}

LLVM IR (-O2):
define void @shallow2dv_speed(float* noalias nocapture %0, float* noalias nocapture %1, float* noalias nocapture %2, float* noalias nocapture %3, float %4, i32 %5) {
%7 = bitcast float* %0 to <2 x float>*
%8 = load <2 x float>, <2 x float>* %7
%9 = icmp sgt i32 %5, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = zext i32 %5 to i64
br label %17
12: ; preds = %17, %6
%13 = phi <2 x float> [ %8, %6 ], [ %39, %17 ]
%14 = getelementptr inbounds float, float* %0, i64 1
%15 = extractelement <2 x float> %13, i64 0
store float %15, float* %0
%16 = extractelement <2 x float> %13, i64 1
store float %16, float* %14
ret void
17: ; preds = %10, %17
%18 = phi i64 [ 0, %10 ], [ %40, %17 ]
%19 = phi <2 x float> [ %8, %10 ], [ %39, %17 ]
%20 = getelementptr inbounds float, float* %1, i64 %18
%21 = load float, float* %20
%22 = fdiv float 1.000000e+00, %21
%23 = fmul float %21, %4
%24 = tail call float @sqrtf(float %23)
%25 = getelementptr inbounds float, float* %2, i64 %18
%26 = load float, float* %25
%27 = getelementptr inbounds float, float* %3, i64 %18
%28 = load float, float* %27
%29 = insertelement <2 x float> poison, float %22, i64 0
%30 = shufflevector <2 x float> %29, <2 x float> poison, <2 x i32> zeroinitializer
%31 = insertelement <2 x float> poison, float %26, i64 0
%32 = insertelement <2 x float> %31, float %28, i64 1
%33 = fmul <2 x float> %30, %32
%34 = call <2 x float> @llvm.fabs.v2f32(<2 x float> %33)
%35 = insertelement <2 x float> poison, float %24, i64 0
%36 = shufflevector <2 x float> %35, <2 x float> poison, <2 x i32> zeroinitializer
%37 = fadd <2 x float> %36, %34
%38 = fcmp olt <2 x float> %19, %37
%39 = select <2 x i1> %38, <2 x float> %37, <2 x float> %19
%40 = add nuw nsw i64 %18, 1
%41 = icmp eq i64 %40, %11
br i1 %41, label %12, label %17
}