void compute_vector_delta(double *v, double *u, int length) {
  int i;
  int lm1 = length - 1;
  for (i = 0; i < lm1; i++)
    v[i] = u[i + 1] - u[i];
  v[length - 1] = 0.0;
}


x86 assembly (clang, -O0):
<compute_vector_delta>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1165 <compute_vector_delta+0x65>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    111f <compute_vector_delta+0x1f>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_vector_delta>:
lea    -0x1(%rdx),%r8d
cmp    $0x2,%edx
jl     12b4 <compute_vector_delta+0x1b4>
mov    %r8d,%r10d
cmp    $0x4,%r8d
jb     1134 <compute_vector_delta+0x34>
lea    (%rsi,%r10,8),%rax
add    $0x8,%rax
cmp    %rdi,%rax
jbe    11e7 <compute_vector_delta+0xe7>
lea    (%rdi,%r10,8),%rax
cmp    %rsi,%rax
jbe    11e7 <compute_vector_delta+0xe7>
xor    %edx,%edx
mov    %rdx,%r9
not    %r9
add    %r10,%r9
mov    %r10,%rcx
and    $0x3,%rcx
je     1179 <compute_vector_delta+0x79>
nopl   0x0(%rax,%rax,1)
lea    0x1(%rdx),%rax
movsd  0x8(%rsi,%rdx,8),%xmm0
subsd  (%rsi,%rdx,8),%xmm0
movsd  %xmm0,(%rdi,%rdx,8)
mov    %rax,%rdx
add    $0xffffffffffffffff,%rcx
jne    1150 <compute_vector_delta+0x50>
cmp    $0x3,%r9
jb     12b4 <compute_vector_delta+0x1b4>
jmp    1190 <compute_vector_delta+0x90>
mov    %rdx,%rax
cmp    $0x3,%r9
jb     12b4 <compute_vector_delta+0x1b4>
cs nopw 0x0(%rax,%rax,1)
movsd  0x8(%rsi,%rax,8),%xmm0
subsd  (%rsi,%rax,8),%xmm0
movsd  %xmm0,(%rdi,%rax,8)
movsd  0x10(%rsi,%rax,8),%xmm0
subsd  0x8(%rsi,%rax,8),%xmm0
movsd  %xmm0,0x8(%rdi,%rax,8)
movsd  0x18(%rsi,%rax,8),%xmm0
subsd  0x10(%rsi,%rax,8),%xmm0
movsd  %xmm0,0x10(%rdi,%rax,8)
movsd  0x20(%rsi,%rax,8),%xmm0
subsd  0x18(%rsi,%rax,8),%xmm0
movsd  %xmm0,0x18(%rdi,%rax,8)
lea    0x4(%rax),%rcx
mov    %rcx,%rax
cmp    %rcx,%r10
jne    1190 <compute_vector_delta+0x90>
jmp    12b4 <compute_vector_delta+0x1b4>
mov    %r10d,%edx
and    $0xfffffffc,%edx
lea    -0x4(%rdx),%rax
mov    %rax,%r9
shr    $0x2,%r9
add    $0x1,%r9
test   %rax,%rax
je     12c0 <compute_vector_delta+0x1c0>
mov    %r9,%rcx
and    $0xfffffffffffffffe,%rcx
xor    %eax,%eax
xchg   %ax,%ax
movupd (%rsi,%rax,8),%xmm0
movupd 0x8(%rsi,%rax,8),%xmm1
subpd  %xmm0,%xmm1
movupd 0x10(%rsi,%rax,8),%xmm0
movupd 0x18(%rsi,%rax,8),%xmm2
subpd  %xmm0,%xmm2
movupd %xmm1,(%rdi,%rax,8)
movupd %xmm2,0x10(%rdi,%rax,8)
movupd 0x20(%rsi,%rax,8),%xmm0
movupd 0x28(%rsi,%rax,8),%xmm1
subpd  %xmm0,%xmm1
movupd 0x30(%rsi,%rax,8),%xmm0
movupd 0x38(%rsi,%rax,8),%xmm2
subpd  %xmm0,%xmm2
movupd %xmm1,0x20(%rdi,%rax,8)
movupd %xmm2,0x30(%rdi,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%rcx
jne    1210 <compute_vector_delta+0x110>
test   $0x1,%r9b
je     12ab <compute_vector_delta+0x1ab>
lea    0x0(,%rax,8),%rcx
or     $0x8,%rcx
movupd (%rsi,%rcx,1),%xmm0
movupd 0x10(%rsi,%rcx,1),%xmm1
movupd (%rsi,%rax,8),%xmm2
subpd  %xmm2,%xmm0
movupd 0x10(%rsi,%rax,8),%xmm2
subpd  %xmm2,%xmm1
movupd %xmm0,(%rdi,%rax,8)
movupd %xmm1,0x10(%rdi,%rax,8)
cmp    %r10,%rdx
jne    1136 <compute_vector_delta+0x36>
movslq %r8d,%rax
movq   $0x0,(%rdi,%rax,8)
ret
xor    %eax,%eax
test   $0x1,%r9b
jne    1276 <compute_vector_delta+0x176>
jmp    12ab <compute_vector_delta+0x1ab>

LLVM IR (-O0):
define void @compute_vector_delta(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %32, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %11
%16 = load double*, double** %5
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %16, i64 %19
%21 = load double, double* %20
%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
%27 = fsub double %21, %26
%28 = load double*, double** %4
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
store double %27, double* %31
br label %32
32: ; preds = %15
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %11
35: ; preds = %11
%36 = load double*, double** %4
%37 = load i32, i32* %6
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %36, i64 %39
store double 0.000000e+00, double* %40
ret void
}

LLVM IR (-O2):
define void @compute_vector_delta(double* nocapture writeonly %0, double* nocapture %1, i32 %2) {
%4 = add i32 %2, -1
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %147
6: ; preds = %3
%7 = zext i32 %4 to i64
%8 = icmp ult i32 %4, 4
br i1 %8, label %95, label %9
9: ; preds = %6
%10 = getelementptr double, double* %0, i64 %7
%11 = add nuw nsw i64 %7, 1
%12 = getelementptr double, double* %1, i64 %11
%13 = icmp ugt double* %12, %0
%14 = icmp ugt double* %10, %1
%15 = and i1 %13, %14
br i1 %15, label %95, label %16
16: ; preds = %9
%17 = and i64 %7, 4294967292
%18 = add nsw i64 %17, -4
%19 = lshr exact i64 %18, 2
%20 = add nuw nsw i64 %19, 1
%21 = and i64 %20, 1
%22 = icmp eq i64 %18, 0
br i1 %22, label %70, label %23
23: ; preds = %16
%24 = and i64 %20, 9223372036854775806
br label %25
25: ; preds = %25, %23
%26 = phi i64 [ 0, %23 ], [ %67, %25 ]
%27 = phi i64 [ 0, %23 ], [ %68, %25 ]
%28 = or i64 %26, 1
%29 = getelementptr inbounds double, double* %1, i64 %28
%30 = bitcast double* %29 to <2 x double>*
%31 = load <2 x double>, <2 x double>* %30
%32 = getelementptr inbounds double, double* %29, i64 2
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = getelementptr inbounds double, double* %1, i64 %26
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = getelementptr inbounds double, double* %35, i64 2
%39 = bitcast double* %38 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = fsub <2 x double> %31, %37
%42 = fsub <2 x double> %34, %40
%43 = getelementptr inbounds double, double* %0, i64 %26
%44 = bitcast double* %43 to <2 x double>*
store <2 x double> %41, <2 x double>* %44
%45 = getelementptr inbounds double, double* %43, i64 2
%46 = bitcast double* %45 to <2 x double>*
store <2 x double> %42, <2 x double>* %46
%47 = or i64 %26, 4
%48 = or i64 %26, 5
%49 = getelementptr inbounds double, double* %1, i64 %48
%50 = bitcast double* %49 to <2 x double>*
%51 = load <2 x double>, <2 x double>* %50
%52 = getelementptr inbounds double, double* %49, i64 2
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = getelementptr inbounds double, double* %1, i64 %47
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = getelementptr inbounds double, double* %55, i64 2
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = fsub <2 x double> %51, %57
%62 = fsub <2 x double> %54, %60
%63 = getelementptr inbounds double, double* %0, i64 %47
%64 = bitcast double* %63 to <2 x double>*
store <2 x double> %61, <2 x double>* %64
%65 = getelementptr inbounds double, double* %63, i64 2
%66 = bitcast double* %65 to <2 x double>*
store <2 x double> %62, <2 x double>* %66
%67 = add nuw i64 %26, 8
%68 = add i64 %27, 2
%69 = icmp eq i64 %68, %24
br i1 %69, label %70, label %25
70: ; preds = %25, %16
%71 = phi i64 [ 0, %16 ], [ %67, %25 ]
%72 = icmp eq i64 %21, 0
br i1 %72, label %93, label %73
73: ; preds = %70
%74 = or i64 %71, 1
%75 = getelementptr inbounds double, double* %1, i64 %74
%76 = bitcast double* %75 to <2 x double>*
%77 = load <2 x double>, <2 x double>* %76
%78 = getelementptr inbounds double, double* %75, i64 2
%79 = bitcast double* %78 to <2 x double>*
%80 = load <2 x double>, <2 x double>* %79
%81 = getelementptr inbounds double, double* %1, i64 %71
%82 = bitcast double* %81 to <2 x double>*
%83 = load <2 x double>, <2 x double>* %82
%84 = getelementptr inbounds double, double* %81, i64 2
%85 = bitcast double* %84 to <2 x double>*
%86 = load <2 x double>, <2 x double>* %85
%87 = fsub <2 x double> %77, %83
%88 = fsub <2 x double> %80, %86
%89 = getelementptr inbounds double, double* %0, i64 %71
%90 = bitcast double* %89 to <2 x double>*
store <2 x double> %87, <2 x double>* %90
%91 = getelementptr inbounds double, double* %89, i64 2
%92 = bitcast double* %91 to <2 x double>*
store <2 x double> %88, <2 x double>* %92
br label %93
93: ; preds = %70, %73
%94 = icmp eq i64 %17, %7
br i1 %94, label %147, label %95
95: ; preds = %9, %6, %93
%96 = phi i64 [ 0, %9 ], [ 0, %6 ], [ %17, %93 ]
%97 = xor i64 %96, -1
%98 = add nsw i64 %97, %7
%99 = and i64 %7, 3
%100 = icmp eq i64 %99, 0
br i1 %100, label %113, label %101
101: ; preds = %95, %101
%102 = phi i64 [ %104, %101 ], [ %96, %95 ]
%103 = phi i64 [ %111, %101 ], [ 0, %95 ]
%104 = add nuw nsw i64 %102, 1
%105 = getelementptr inbounds double, double* %1, i64 %104
%106 = load double, double* %105
%107 = getelementptr inbounds double, double* %1, i64 %102
%108 = load double, double* %107
%109 = fsub double %106, %108
%110 = getelementptr inbounds double, double* %0, i64 %102
store double %109, double* %110
%111 = add i64 %103, 1
%112 = icmp eq i64 %111, %99
br i1 %112, label %113, label %101
113: ; preds = %101, %95
%114 = phi i64 [ %96, %95 ], [ %104, %101 ]
%115 = icmp ult i64 %98, 3
br i1 %115, label %147, label %116
116: ; preds = %113, %116
%117 = phi i64 [ %139, %116 ], [ %114, %113 ]
%118 = add nuw nsw i64 %117, 1
%119 = getelementptr inbounds double, double* %1, i64 %118
%120 = load double, double* %119
%121 = getelementptr inbounds double, double* %1, i64 %117
%122 = load double, double* %121
%123 = fsub double %120, %122
%124 = getelementptr inbounds double, double* %0, i64 %117
store double %123, double* %124
%125 = add nuw nsw i64 %117, 2
%126 = getelementptr inbounds double, double* %1, i64 %125
%127 = load double, double* %126
%128 = getelementptr inbounds double, double* %1, i64 %118
%129 = load double, double* %128
%130 = fsub double %127, %129
%131 = getelementptr inbounds double, double* %0, i64 %118
store double %130, double* %131
%132 = add nuw nsw i64 %117, 3
%133 = getelementptr inbounds double, double* %1, i64 %132
%134 = load double, double* %133
%135 = getelementptr inbounds double, double* %1, i64 %125
%136 = load double, double* %135
%137 = fsub double %134, %136
%138 = getelementptr inbounds double, double* %0, i64 %125
store double %137, double* %138
%139 = add nuw nsw i64 %117, 4
%140 = getelementptr inbounds double, double* %1, i64 %139
%141 = load double, double* %140
%142 = getelementptr inbounds double, double* %1, i64 %132
%143 = load double, double* %142
%144 = fsub double %141, %143
%145 = getelementptr inbounds double, double* %0, i64 %132
store double %144, double* %145
%146 = icmp eq i64 %139, %7
br i1 %146, label %147, label %116
147: ; preds = %113, %116, %93, %3
%148 = sext i32 %4 to i64
%149 = getelementptr inbounds double, double* %0, i64 %148
store double 0.000000e+00, double* %149
ret void
}