void push_double_vector(double new_value, double *dvec, int value_pos,
                        int vec_length) {
  int i;
  if ((value_pos > 0) & (value_pos <= vec_length)) {
    for (i = 1; i <= (value_pos - 1); i++)
      dvec[i] = dvec[i + 1];
    dvec[value_pos] = new_value;
  }
}


x86 assembly (clang, -O0):
<push_double_vector>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x14(%rbp),%ecx
cmp    -0x18(%rbp),%ecx
setle  %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1190 <push_double_vector+0x90>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     117e <push_double_vector+0x7e>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1140 <push_double_vector+0x40>
movsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
pop    %rbp
ret

x86 assembly (clang, -O2):
<push_double_vector>:
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    114c <push_double_vector+0x3c>
mov    %esi,%ebx
cmp    %edx,%esi
jg     114c <push_double_vector+0x3c>
mov    %rdi,%r14
cmp    $0x2,%ebx
jb     1144 <push_double_vector+0x34>
lea    0x8(%r14),%rdi
lea    0x10(%r14),%rsi
lea    -0x1(%rbx),%edx
shl    $0x3,%rdx
movsd  %xmm0,(%rsp)
call   1030 <memmove@plt>
movsd  (%rsp),%xmm0
mov    %ebx,%eax
movsd  %xmm0,(%r14,%rax,8)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @push_double_vector(double %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store double %0, double* %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %7
%11 = icmp sgt i32 %10, 0
%12 = zext i1 %11 to i32
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = icmp sle i32 %13, %14
%16 = zext i1 %15 to i32
%17 = and i32 %12, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %45
19: ; preds = %4
store i32 1, i32* %9
br label %20
20: ; preds = %36, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = sub nsw i32 %22, 1
%24 = icmp sle i32 %21, %23
br i1 %24, label %25, label %39
25: ; preds = %20
%26 = load double*, double** %6
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %26, i64 %29
%31 = load double, double* %30
%32 = load double*, double** %6
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
store double %31, double* %35
br label %36
36: ; preds = %25
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %20
39: ; preds = %20
%40 = load double, double* %5
%41 = load double*, double** %6
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
store double %40, double* %44
br label %45
45: ; preds = %39, %4
ret void
}

LLVM IR (-O2):
define void @push_double_vector(double %0, double* nocapture %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
%6 = icmp sle i32 %2, %3
%7 = and i1 %5, %6
br i1 %7, label %8, label %21
8: ; preds = %4
%9 = icmp ugt i32 %2, 1
br i1 %9, label %10, label %18
10: ; preds = %8
%11 = getelementptr double, double* %1, i64 1
%12 = bitcast double* %11 to i8*
%13 = getelementptr double, double* %1, i64 2
%14 = bitcast double* %13 to i8*
%15 = add nsw i32 %2, -1
%16 = zext i32 %15 to i64
%17 = shl nuw nsw i64 %16, 3
br label %18
18: ; preds = %10, %8
%19 = zext i32 %2 to i64
%20 = getelementptr inbounds double, double* %1, i64 %19
store double %0, double* %20
br label %21
21: ; preds = %18, %4
ret void
}