void half_double_vector(int size, double *vec) {
  int i;
  for (i = 0; i < size; i++)
    vec[i] /= 2.;
}


x86 assembly (clang, -O0):
<half_double_vector>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    114a <half_double_vector+0x4a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xecd(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1112 <half_double_vector+0x12>
pop    %rbp
ret

x86 assembly (clang, -O2):
<half_double_vector>:
test   %edi,%edi
jle    11f7 <half_double_vector+0xf7>
mov    %edi,%eax
cmp    $0x4,%edi
jae    1116 <half_double_vector+0x16>
xor    %ecx,%ecx
jmp    11c9 <half_double_vector+0xc9>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdx
mov    %rdx,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rdx,%rdx
je     11f8 <half_double_vector+0xf8>
mov    %r8,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %edx,%edx
movapd 0xebc(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movupd (%rsi,%rdx,8),%xmm1
movupd 0x10(%rsi,%rdx,8),%xmm2
movupd 0x20(%rsi,%rdx,8),%xmm3
movupd 0x30(%rsi,%rdx,8),%xmm4
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,(%rsi,%rdx,8)
movupd %xmm2,0x10(%rsi,%rdx,8)
mulpd  %xmm0,%xmm3
mulpd  %xmm0,%xmm4
movupd %xmm3,0x20(%rsi,%rdx,8)
movupd %xmm4,0x30(%rsi,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rdi
jne    1150 <half_double_vector+0x50>
test   $0x1,%r8b
je     11c4 <half_double_vector+0xc4>
movupd (%rsi,%rdx,8),%xmm0
movupd 0x10(%rsi,%rdx,8),%xmm1
movapd 0xe4f(%rip),%xmm2
mulpd  %xmm2,%xmm0
mulpd  %xmm2,%xmm1
movupd %xmm0,(%rsi,%rdx,8)
movupd %xmm1,0x10(%rsi,%rdx,8)
cmp    %rax,%rcx
je     11f7 <half_double_vector+0xf7>
movsd  0xe3f(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rsi,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11e0 <half_double_vector+0xe0>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    119e <half_double_vector+0x9e>
jmp    11c4 <half_double_vector+0xc4>

LLVM IR (-O0):
define void @half_double_vector(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
store i32 %0, i32* %3
store double* %1, double** %4
store i32 0, i32* %5
br label %6
6: ; preds = %17, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %3
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = load double*, double** %4
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %11, i64 %13
%15 = load double, double* %14
%16 = fdiv double %15, 2.000000e+00
store double %16, double* %14
br label %17
17: ; preds = %10
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %6
20: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @half_double_vector(i32 %0, double* nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %68
4: ; preds = %2
%5 = zext i32 %0 to i64
%6 = icmp ult i32 %0, 4
br i1 %6, label %59, label %7
7: ; preds = %4
%8 = and i64 %5, 4294967292
%9 = add nsw i64 %8, -4
%10 = lshr exact i64 %9, 2
%11 = add nuw nsw i64 %10, 1
%12 = and i64 %11, 1
%13 = icmp eq i64 %9, 0
br i1 %13, label %43, label %14
14: ; preds = %7
%15 = and i64 %11, 9223372036854775806
br label %16
16: ; preds = %16, %14
%17 = phi i64 [ 0, %14 ], [ %40, %16 ]
%18 = phi i64 [ 0, %14 ], [ %41, %16 ]
%19 = getelementptr inbounds double, double* %1, i64 %17
%20 = bitcast double* %19 to <2 x double>*
%21 = load <2 x double>, <2 x double>* %20
%22 = getelementptr inbounds double, double* %19, i64 2
%23 = bitcast double* %22 to <2 x double>*
%24 = load <2 x double>, <2 x double>* %23
%25 = fmul <2 x double> %21, <double 5.000000e-01, double 5.000000e-01>
%26 = fmul <2 x double> %24, <double 5.000000e-01, double 5.000000e-01>
%27 = bitcast double* %19 to <2 x double>*
store <2 x double> %25, <2 x double>* %27
%28 = bitcast double* %22 to <2 x double>*
store <2 x double> %26, <2 x double>* %28
%29 = or i64 %17, 4
%30 = getelementptr inbounds double, double* %1, i64 %29
%31 = bitcast double* %30 to <2 x double>*
%32 = load <2 x double>, <2 x double>* %31
%33 = getelementptr inbounds double, double* %30, i64 2
%34 = bitcast double* %33 to <2 x double>*
%35 = load <2 x double>, <2 x double>* %34
%36 = fmul <2 x double> %32, <double 5.000000e-01, double 5.000000e-01>
%37 = fmul <2 x double> %35, <double 5.000000e-01, double 5.000000e-01>
%38 = bitcast double* %30 to <2 x double>*
store <2 x double> %36, <2 x double>* %38
%39 = bitcast double* %33 to <2 x double>*
store <2 x double> %37, <2 x double>* %39
%40 = add nuw i64 %17, 8
%41 = add i64 %18, 2
%42 = icmp eq i64 %41, %15
br i1 %42, label %43, label %16
43: ; preds = %16, %7
%44 = phi i64 [ 0, %7 ], [ %40, %16 ]
%45 = icmp eq i64 %12, 0
br i1 %45, label %57, label %46
46: ; preds = %43
%47 = getelementptr inbounds double, double* %1, i64 %44
%48 = bitcast double* %47 to <2 x double>*
%49 = load <2 x double>, <2 x double>* %48
%50 = getelementptr inbounds double, double* %47, i64 2
%51 = bitcast double* %50 to <2 x double>*
%52 = load <2 x double>, <2 x double>* %51
%53 = fmul <2 x double> %49, <double 5.000000e-01, double 5.000000e-01>
%54 = fmul <2 x double> %52, <double 5.000000e-01, double 5.000000e-01>
%55 = bitcast double* %47 to <2 x double>*
store <2 x double> %53, <2 x double>* %55
%56 = bitcast double* %50 to <2 x double>*
store <2 x double> %54, <2 x double>* %56
br label %57
57: ; preds = %43, %46
%58 = icmp eq i64 %8, %5
br i1 %58, label %68, label %59
59: ; preds = %4, %57
%60 = phi i64 [ 0, %4 ], [ %8, %57 ]
br label %61
61: ; preds = %59, %61
%62 = phi i64 [ %66, %61 ], [ %60, %59 ]
%63 = getelementptr inbounds double, double* %1, i64 %62
%64 = load double, double* %63
%65 = fmul double %64, 5.000000e-01
store double %65, double* %63
%66 = add nuw nsw i64 %62, 1
%67 = icmp eq i64 %66, %5
br i1 %67, label %68, label %61
68: ; preds = %61, %57, %2
ret void
}