#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 */
typedef int uint32_t;

/* Variables and functions */
scalar_t__ local_kernelSPH(int /*<<< orphan*/);
int /*<<< orphan*/ ndim_array_access_lin2n(int, int, int, int /*<<< orphan*/,
                                           int *);
int /*<<< orphan*/ sqrt(double);
double local_calcKernelSPHSubSample(const uint32_t *k, double kernelMin,
                                    double subCellWidth, double cellWidth) {
  uint32_t kSub[3];
  double r, pos;
  double subSample = 0.0;
  for (uint32_t j = 0; j < ((8) * (8) * (8)); j++) {
    ndim_array_access_lin2n(3, j, 8, 0, kSub);
    r = 0.0;
    for (uint32_t n = 0; n < 3; n++) {
      pos = kernelMin + (k[n] + (kSub[n] + 0.5) * subCellWidth) * cellWidth;
      r += pos * pos;
    }
    subSample += local_kernelSPH(sqrt(r));
  }
  return subSample;
}


x86 assembly (clang, -O0):
<local_calcKernelSPHSubSample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x200,-0x4c(%rbp)
jge    1237 <local_calcKernelSPHSubSample+0x107>
mov    -0x4c(%rbp),%esi
lea    -0x2c(%rbp),%r8
mov    $0x3,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <ndim_array_access_lin2n@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x50(%rbp)
cmpl   $0x3,-0x50(%rbp)
jge    1209 <local_calcKernelSPHSubSample+0xd9>
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x50(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm2
movslq -0x50(%rbp),%rax
cvtsi2sdl -0x2c(%rbp,%rax,4),%xmm0
movsd  0xe44(%rip),%xmm3
addsd  %xmm3,%xmm0
movsd  -0x18(%rbp),%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    118e <local_calcKernelSPHSubSample+0x5e>
movsd  -0x38(%rbp),%xmm0
call   1050 <sqrt@plt>
mov    %eax,%edi
call   1030 <local_kernelSPH@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    115a <local_calcKernelSPHSubSample+0x2a>
movsd  -0x48(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_calcKernelSPHSubSample>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
movsd  %xmm2,0x28(%rsp)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x18(%rsp)
mov    %rdi,%rbx
xor    %ebp,%ebp
lea    0xc(%rsp),%r14
xorps  %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    $0x3,%edi
mov    %ebp,%esi
mov    $0x8,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <ndim_array_access_lin2n@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl (%rbx),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl 0xc(%rsp),%xmm1
movsd  0xe6d(%rip),%xmm7
addsd  %xmm7,%xmm1
movsd  0x20(%rsp),%xmm5
mulsd  %xmm5,%xmm1
addsd  %xmm0,%xmm1
movsd  0x28(%rsp),%xmm4
mulsd  %xmm4,%xmm1
movsd  0x18(%rsp),%xmm6
addsd  %xmm6,%xmm1
mulsd  %xmm1,%xmm1
addsd  0xe43(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdl 0x4(%rbx),%xmm0
xorps  %xmm2,%xmm2
cvtsi2sdl 0x10(%rsp),%xmm2
addsd  %xmm7,%xmm2
mulsd  %xmm5,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm4,%xmm2
addsd  %xmm6,%xmm2
mulsd  %xmm2,%xmm2
xorps  %xmm3,%xmm3
cvtsi2sdl 0x8(%rbx),%xmm3
xorps  %xmm0,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm0
addsd  %xmm1,%xmm2
addsd  %xmm7,%xmm0
mulsd  %xmm5,%xmm0
addsd  %xmm3,%xmm0
mulsd  %xmm4,%xmm0
addsd  %xmm6,%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
call   1050 <sqrt@plt>
mov    %eax,%edi
call   1030 <local_kernelSPH@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%ebp
cmp    $0x200,%ebp
jne    1160 <local_calcKernelSPHSubSample+0x30>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @local_calcKernelSPHSubSample(i32* %0, double %1, double %2, double %3) {
%5 = alloca i32*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca [3 x i32]
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
store double 0.000000e+00, double* %12
store i32 0, i32* %13
br label %15
15: ; preds = %57, %4
%16 = load i32, i32* %13
%17 = icmp slt i32 %16, 512
br i1 %17, label %18, label %60
18: ; preds = %15
%19 = load i32, i32* %13
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%21 = call i32 @ndim_array_access_lin2n(i32 3, i32 %19, i32 8, i32 0, i32* %20)
store double 0.000000e+00, double* %10
store i32 0, i32* %14
br label %22
22: ; preds = %47, %18
%23 = load i32, i32* %14
%24 = icmp slt i32 %23, 3
br i1 %24, label %25, label %50
25: ; preds = %22
%26 = load double, double* %6
%27 = load i32*, i32** %5
%28 = load i32, i32* %14
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = sitofp i32 %31 to double
%33 = load i32, i32* %14
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = sitofp i32 %36 to double
%38 = fadd double %37, 5.000000e-01
%39 = load double, double* %7
%40 = call double @llvm.fmuladd.f64(double %38, double %39, double %32)
%41 = load double, double* %8
%42 = call double @llvm.fmuladd.f64(double %40, double %41, double %26)
store double %42, double* %11
%43 = load double, double* %11
%44 = load double, double* %11
%45 = load double, double* %10
%46 = call double @llvm.fmuladd.f64(double %43, double %44, double %45)
store double %46, double* %10
br label %47
47: ; preds = %25
%48 = load i32, i32* %14
%49 = add nsw i32 %48, 1
store i32 %49, i32* %14
br label %22
50: ; preds = %22
%51 = load double, double* %10
%52 = call i32 @sqrt(double %51)
%53 = call i64 @local_kernelSPH(i32 %52)
%54 = sitofp i64 %53 to double
%55 = load double, double* %12
%56 = fadd double %55, %54
store double %56, double* %12
br label %57
57: ; preds = %50
%58 = load i32, i32* %13
%59 = add nsw i32 %58, 1
store i32 %59, i32* %13
br label %15
60: ; preds = %15
%61 = load double, double* %12
ret double %61
}

LLVM IR (-O2):
define double @local_calcKernelSPHSubSample(i32* nocapture %0, double %1, double %2, double %3) {
%5 = alloca [3 x i32]
%6 = bitcast [3 x i32]* %5 to i8*
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%8 = getelementptr inbounds i32, i32* %0, i64 1
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%10 = getelementptr inbounds i32, i32* %0, i64 2
%11 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
br label %13
12: ; preds = %13
ret double %44
13: ; preds = %4, %13
%14 = phi i32 [ 0, %4 ], [ %45, %13 ]
%15 = phi double [ 0.000000e+00, %4 ], [ %44, %13 ]
%16 = call i32 @ndim_array_access_lin2n(i32 3, i32 %14, i32 8, i32 0, i32* %7)
%17 = load i32, i32* %0
%18 = sitofp i32 %17 to double
%19 = load i32, i32* %7
%20 = sitofp i32 %19 to double
%21 = fadd double %20, 5.000000e-01
%22 = call double @llvm.fmuladd.f64(double %21, double %2, double %18)
%23 = call double @llvm.fmuladd.f64(double %22, double %3, double %1)
%24 = call double @llvm.fmuladd.f64(double %23, double %23, double 0.000000e+00)
%25 = load i32, i32* %8
%26 = sitofp i32 %25 to double
%27 = load i32, i32* %9
%28 = sitofp i32 %27 to double
%29 = fadd double %28, 5.000000e-01
%30 = call double @llvm.fmuladd.f64(double %29, double %2, double %26)
%31 = call double @llvm.fmuladd.f64(double %30, double %3, double %1)
%32 = call double @llvm.fmuladd.f64(double %31, double %31, double %24)
%33 = load i32, i32* %10
%34 = sitofp i32 %33 to double
%35 = load i32, i32* %11
%36 = sitofp i32 %35 to double
%37 = fadd double %36, 5.000000e-01
%38 = call double @llvm.fmuladd.f64(double %37, double %2, double %34)
%39 = call double @llvm.fmuladd.f64(double %38, double %3, double %1)
%40 = call double @llvm.fmuladd.f64(double %39, double %39, double %32)
%41 = call i32 @sqrt(double %40)
%42 = call i64 @local_kernelSPH(i32 %41)
%43 = sitofp i64 %42 to double
%44 = fadd double %15, %43
%45 = add nuw nsw i32 %14, 1
%46 = icmp eq i32 %45, 512
br i1 %46, label %12, label %13
}