void kernel(double *v1, double *v2, int m, int n) {
  double phi_e = *(v1 + 1);
  double phi_w = *(v1 - 1);
  double phi_n = *(v1 + m);
  double phi_s = *(v1 - m);
  double phi_u = *(v1 + m * n);
  double phi_d = *(v1 - m * n);
  double phi = 1. / 6. * (phi_e + phi_w + phi_n + phi_s + phi_u + phi_d);
  *(v2) = phi;
}


x86 assembly (clang, -O0):
<kernel>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm1
addsd  -0x28(%rbp),%xmm1
addsd  -0x30(%rbp),%xmm1
addsd  -0x38(%rbp),%xmm1
addsd  -0x40(%rbp),%xmm1
addsd  -0x48(%rbp),%xmm1
movsd  0xe4e(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel>:
movsd  0x8(%rdi),%xmm0
movslq %edx,%rax
lea    0x0(,%rax,8),%r8
mov    %rdi,%rdx
sub    %r8,%rdx
addsd  -0x8(%rdi),%xmm0
addsd  (%rdi,%rax,8),%xmm0
imul   %ecx,%eax
cltq
addsd  (%rdx),%xmm0
addsd  (%rdi,%rax,8),%xmm0
lea    0x0(,%rax,8),%rax
sub    %rax,%rdi
addsd  (%rdi),%xmm0
mulsd  0xebb(%rip),%xmm0
movsd  %xmm0,(%rsi)
ret

LLVM IR (-O0):
define void @kernel(double* %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%16 = load double*, double** %5
%17 = getelementptr inbounds double, double* %16, i64 1
%18 = load double, double* %17
store double %18, double* %9
%19 = load double*, double** %5
%20 = getelementptr inbounds double, double* %19, i64 -1
%21 = load double, double* %20
store double %21, double* %10
%22 = load double*, double** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
store double %26, double* %11
%27 = load double*, double** %5
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = sub i64 0, %29
%31 = getelementptr inbounds double, double* %27, i64 %30
%32 = load double, double* %31
store double %32, double* %12
%33 = load double*, double** %5
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = mul nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %33, i64 %37
%39 = load double, double* %38
store double %39, double* %13
%40 = load double*, double** %5
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = mul nsw i32 %41, %42
%44 = sext i32 %43 to i64
%45 = sub i64 0, %44
%46 = getelementptr inbounds double, double* %40, i64 %45
%47 = load double, double* %46
store double %47, double* %14
%48 = load double, double* %9
%49 = load double, double* %10
%50 = fadd double %48, %49
%51 = load double, double* %11
%52 = fadd double %50, %51
%53 = load double, double* %12
%54 = fadd double %52, %53
%55 = load double, double* %13
%56 = fadd double %54, %55
%57 = load double, double* %14
%58 = fadd double %56, %57
%59 = fmul double 0x3FC5555555555555, %58
store double %59, double* %15
%60 = load double, double* %15
%61 = load double*, double** %6
store double %60, double* %61
ret void
}

LLVM IR (-O2):
define void @kernel(double* nocapture %0, double* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = getelementptr inbounds double, double* %0, i64 1
%6 = load double, double* %5
%7 = getelementptr inbounds double, double* %0, i64 -1
%8 = load double, double* %7
%9 = sext i32 %2 to i64
%10 = getelementptr inbounds double, double* %0, i64 %9
%11 = load double, double* %10
%12 = sub nsw i64 0, %9
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = load double, double* %13
%15 = mul nsw i32 %3, %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %0, i64 %16
%18 = load double, double* %17
%19 = sub nsw i64 0, %16
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = load double, double* %20
%22 = fadd double %6, %8
%23 = fadd double %22, %11
%24 = fadd double %23, %14
%25 = fadd double %24, %18
%26 = fadd double %25, %21
%27 = fmul double %26, 0x3FC5555555555555
store double %27, double* %1
ret void
}