void grid_gen_bounds(long n, const double *restrict vals,
                     double *restrict bounds) {
  long i;
  for (i = 0; i < n - 1; ++i) {
    bounds[2 * i + 1] = 0.5 * (vals[i] + vals[i + 1]);
    bounds[2 * (i + 1)] = 0.5 * (vals[i] + vals[i + 1]);
  }
  bounds[0] = 2 * vals[0] - bounds[1];
  bounds[2 * n - 1] = 2 * vals[n - 1] - bounds[2 * (n - 1)];
}


x86 assembly (clang, -O0):
<grid_gen_bounds>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jge    11b3 <grid_gen_bounds+0xb3>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
addsd  0x8(%rax,%rcx,8),%xmm1
movsd  0xeb0(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsd  %xmm0,0x8(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
addsd  0x8(%rax,%rcx,8),%xmm1
movsd  0xe77(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
shl    $0x1,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1118 <grid_gen_bounds+0x18>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    $0x1,%rcx
shl    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
shl    $0x1,%rcx
sub    $0x1,%rcx
movsd  %xmm0,(%rax,%rcx,8)
pop    %rbp
ret

x86 assembly (clang, -O2):
<grid_gen_bounds>:
lea    -0x1(%rdi),%r8
movsd  (%rsi),%xmm0
cmp    $0x2,%rdi
jl     11e7 <grid_gen_bounds+0xe7>
cmp    $0x4,%r8
jae    1124 <grid_gen_bounds+0x24>
xor    %r9d,%r9d
movapd %xmm0,%xmm1
jmp    11a7 <grid_gen_bounds+0xa7>
mov    %r8,%r9
and    $0xfffffffffffffffc,%r9
unpcklpd %xmm0,%xmm1
lea    0x28(%rdx),%rax
xor    %ecx,%ecx
movapd 0xec3(%rip),%xmm2
nopl   (%rax)
movupd 0x8(%rsi,%rcx,8),%xmm3
shufpd $0x1,%xmm3,%xmm1
addpd  %xmm3,%xmm1
mulpd  %xmm2,%xmm1
movapd %xmm1,%xmm4
unpckhpd %xmm1,%xmm1
movupd %xmm1,-0x10(%rax)
movupd 0x18(%rsi,%rcx,8),%xmm1
shufpd $0x1,%xmm1,%xmm3
addpd  %xmm1,%xmm3
mulpd  %xmm2,%xmm3
unpcklpd %xmm4,%xmm4
movupd %xmm4,-0x20(%rax)
movapd %xmm3,%xmm4
unpcklpd %xmm3,%xmm4
unpckhpd %xmm3,%xmm3
movupd %xmm3,0x10(%rax)
movupd %xmm4,(%rax)
add    $0x4,%rcx
add    $0x40,%rax
cmp    %rcx,%r9
jne    1140 <grid_gen_bounds+0x40>
cmp    %r9,%r8
je     11e7 <grid_gen_bounds+0xe7>
unpckhpd %xmm1,%xmm1
lea    0x1(%r9),%rax
shl    $0x4,%r9
lea    (%r9,%rdx,1),%rcx
add    $0x10,%rcx
movsd  0xe51(%rip),%xmm2
nop
movsd  (%rsi,%rax,8),%xmm3
addsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,-0x8(%rcx)
movsd  %xmm1,(%rcx)
add    $0x1,%rax
add    $0x10,%rcx
movapd %xmm3,%xmm1
cmp    %rax,%rdi
jne    11c0 <grid_gen_bounds+0xc0>
addsd  %xmm0,%xmm0
subsd  0x8(%rdx),%xmm0
movsd  %xmm0,(%rdx)
movsd  -0x8(%rsi,%rdi,8),%xmm0
shl    $0x4,%r8
addsd  %xmm0,%xmm0
subsd  (%rdx,%r8,1),%xmm0
shl    $0x4,%rdi
movsd  %xmm0,-0x8(%rdi,%rdx,1)
ret

LLVM IR (-O0):
define void @grid_gen_bounds(i64 %0, double* noalias %1, double* noalias %2) {
%4 = alloca i64
%5 = alloca double*
%6 = alloca double*
%7 = alloca i64
store i64 %0, i64* %4
store double* %1, double** %5
store double* %2, double** %6
store i64 0, i64* %7
br label %8
8: ; preds = %46, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %4
%11 = sub nsw i64 %10, 1
%12 = icmp slt i64 %9, %11
br i1 %12, label %13, label %49
13: ; preds = %8
%14 = load double*, double** %5
%15 = load i64, i64* %7
%16 = getelementptr inbounds double, double* %14, i64 %15
%17 = load double, double* %16
%18 = load double*, double** %5
%19 = load i64, i64* %7
%20 = add nsw i64 %19, 1
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = fadd double %17, %22
%24 = fmul double 5.000000e-01, %23
%25 = load double*, double** %6
%26 = load i64, i64* %7
%27 = mul nsw i64 2, %26
%28 = add nsw i64 %27, 1
%29 = getelementptr inbounds double, double* %25, i64 %28
store double %24, double* %29
%30 = load double*, double** %5
%31 = load i64, i64* %7
%32 = getelementptr inbounds double, double* %30, i64 %31
%33 = load double, double* %32
%34 = load double*, double** %5
%35 = load i64, i64* %7
%36 = add nsw i64 %35, 1
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
%39 = fadd double %33, %38
%40 = fmul double 5.000000e-01, %39
%41 = load double*, double** %6
%42 = load i64, i64* %7
%43 = add nsw i64 %42, 1
%44 = mul nsw i64 2, %43
%45 = getelementptr inbounds double, double* %41, i64 %44
store double %40, double* %45
br label %46
46: ; preds = %13
%47 = load i64, i64* %7
%48 = add nsw i64 %47, 1
store i64 %48, i64* %7
br label %8
49: ; preds = %8
%50 = load double*, double** %5
%51 = getelementptr inbounds double, double* %50, i64 0
%52 = load double, double* %51
%53 = load double*, double** %6
%54 = getelementptr inbounds double, double* %53, i64 1
%55 = load double, double* %54
%56 = fneg double %55
%57 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %52, double %56)
%58 = load double*, double** %6
%59 = getelementptr inbounds double, double* %58, i64 0
store double %57, double* %59
%60 = load double*, double** %5
%61 = load i64, i64* %4
%62 = sub nsw i64 %61, 1
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = load double*, double** %6
%66 = load i64, i64* %4
%67 = sub nsw i64 %66, 1
%68 = mul nsw i64 2, %67
%69 = getelementptr inbounds double, double* %65, i64 %68
%70 = load double, double* %69
%71 = fneg double %70
%72 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %64, double %71)
%73 = load double*, double** %6
%74 = load i64, i64* %4
%75 = mul nsw i64 2, %74
%76 = sub nsw i64 %75, 1
%77 = getelementptr inbounds double, double* %73, i64 %76
store double %72, double* %77
ret void
}

LLVM IR (-O2):
define void @grid_gen_bounds(i64 %0, double* noalias nocapture %1, double* noalias nocapture %2) {
%4 = add i64 %0, -1
%5 = icmp sgt i64 %0, 1
%6 = load double, double* %1
br i1 %5, label %7, label %63
7: ; preds = %3
%8 = icmp ult i64 %4, 4
br i1 %8, label %46, label %9
9: ; preds = %7
%10 = and i64 %4, -4
%11 = insertelement <2 x double> poison, double %6, i64 1
%12 = getelementptr inbounds double, double* %2, i64 -1
%13 = getelementptr inbounds double, double* %2, i64 -1
br label %14
14: ; preds = %14, %9
%15 = phi i64 [ 0, %9 ], [ %41, %14 ]
%16 = phi <2 x double> [ %11, %9 ], [ %23, %14 ]
%17 = or i64 %15, 1
%18 = getelementptr inbounds double, double* %1, i64 %17
%19 = bitcast double* %18 to <2 x double>*
%20 = load <2 x double>, <2 x double>* %19
%21 = getelementptr inbounds double, double* %18, i64 2
%22 = bitcast double* %21 to <2 x double>*
%23 = load <2 x double>, <2 x double>* %22
%24 = shufflevector <2 x double> %16, <2 x double> %20, <2 x i32> <i32 1, i32 2>
%25 = shufflevector <2 x double> %20, <2 x double> %23, <2 x i32> <i32 1, i32 2>
%26 = fadd <2 x double> %24, %20
%27 = fadd <2 x double> %25, %23
%28 = fmul <2 x double> %26, <double 5.000000e-01, double 5.000000e-01>
%29 = fmul <2 x double> %27, <double 5.000000e-01, double 5.000000e-01>
%30 = shl nuw nsw i64 %17, 1
%31 = shl i64 %15, 1
%32 = or i64 %31, 6
%33 = getelementptr inbounds double, double* %12, i64 %30
%34 = bitcast double* %33 to <4 x double>*
%35 = getelementptr inbounds double, double* %13, i64 %32
%36 = bitcast double* %35 to <4 x double>*
%37 = shufflevector <2 x double> %28, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
%38 = shufflevector <4 x double> %37, <4 x double> poison, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
store <4 x double> %38, <4 x double>* %34
%39 = shufflevector <2 x double> %29, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
%40 = shufflevector <4 x double> %39, <4 x double> poison, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
store <4 x double> %40, <4 x double>* %36
%41 = add nuw i64 %15, 4
%42 = icmp eq i64 %41, %10
br i1 %42, label %43, label %14
43: ; preds = %14
%44 = icmp eq i64 %4, %10
%45 = extractelement <2 x double> %23, i64 1
br i1 %44, label %63, label %46
46: ; preds = %7, %43
%47 = phi double [ %45, %43 ], [ %6, %7 ]
%48 = phi i64 [ %10, %43 ], [ 0, %7 ]
br label %49
49: ; preds = %46, %49
%50 = phi double [ %54, %49 ], [ %47, %46 ]
%51 = phi i64 [ %52, %49 ], [ %48, %46 ]
%52 = add nuw nsw i64 %51, 1
%53 = getelementptr inbounds double, double* %1, i64 %52
%54 = load double, double* %53
%55 = fadd double %50, %54
%56 = fmul double %55, 5.000000e-01
%57 = shl nuw nsw i64 %51, 1
%58 = or i64 %57, 1
%59 = getelementptr inbounds double, double* %2, i64 %58
store double %56, double* %59
%60 = shl nuw nsw i64 %52, 1
%61 = getelementptr inbounds double, double* %2, i64 %60
store double %56, double* %61
%62 = icmp eq i64 %52, %4
br i1 %62, label %63, label %49
63: ; preds = %49, %43, %3
%64 = getelementptr inbounds double, double* %2, i64 1
%65 = load double, double* %64
%66 = fneg double %65
%67 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double %66)
store double %67, double* %2
%68 = getelementptr inbounds double, double* %1, i64 %4
%69 = load double, double* %68
%70 = shl nsw i64 %4, 1
%71 = getelementptr inbounds double, double* %2, i64 %70
%72 = load double, double* %71
%73 = fneg double %72
%74 = tail call double @llvm.fmuladd.f64(double %69, double 2.000000e+00, double %73)
%75 = shl nsw i64 %0, 1
%76 = add nsw i64 %75, -1
%77 = getelementptr inbounds double, double* %2, i64 %76
store double %74, double* %77
ret void
}