void setRates(double *r, int rates) {
  int i;
  for (i = 0; i < rates - 1; i++)
    r[i] = 0.5;
  r[rates - 1] = 1.0;
}


x86 assembly (clang, -O0):
<setRates>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1146 <setRates+0x46>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  0xed5(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1112 <setRates+0x12>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xea5(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
pop    %rbp
ret

x86 assembly (clang, -O2):
<setRates>:
lea    -0x1(%rsi),%r8d
cmp    $0x2,%esi
jl     122d <setRates+0x12d>
mov    %r8d,%ecx
cmp    $0x4,%r8d
jae    111d <setRates+0x1d>
xor    %edx,%edx
jmp    1207 <setRates+0x107>
mov    %ecx,%edx
and    $0xfffffffc,%edx
lea    -0x4(%rdx),%rax
mov    %rax,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %esi,%r9d
and    $0x7,%r9d
cmp    $0x1c,%rax
jae    1145 <setRates+0x45>
xor    %eax,%eax
jmp    11d1 <setRates+0xd1>
and    $0xfffffffffffffff8,%rsi
xor    %eax,%eax
movaps 0xeae(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movups %xmm0,(%rdi,%rax,8)
movups %xmm0,0x10(%rdi,%rax,8)
movups %xmm0,0x20(%rdi,%rax,8)
movups %xmm0,0x30(%rdi,%rax,8)
movups %xmm0,0x40(%rdi,%rax,8)
movups %xmm0,0x50(%rdi,%rax,8)
movups %xmm0,0x60(%rdi,%rax,8)
movups %xmm0,0x70(%rdi,%rax,8)
movups %xmm0,0x80(%rdi,%rax,8)
movups %xmm0,0x90(%rdi,%rax,8)
movups %xmm0,0xa0(%rdi,%rax,8)
movups %xmm0,0xb0(%rdi,%rax,8)
movups %xmm0,0xc0(%rdi,%rax,8)
movups %xmm0,0xd0(%rdi,%rax,8)
movups %xmm0,0xe0(%rdi,%rax,8)
movups %xmm0,0xf0(%rdi,%rax,8)
add    $0x20,%rax
add    $0xfffffffffffffff8,%rsi
jne    1160 <setRates+0x60>
test   %r9,%r9
je     1202 <setRates+0x102>
lea    (%rdi,%rax,8),%rax
add    $0x10,%rax
shl    $0x5,%r9
xor    %esi,%esi
movaps 0xe15(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
movups %xmm0,-0x10(%rax,%rsi,1)
movups %xmm0,(%rax,%rsi,1)
add    $0x20,%rsi
cmp    %rsi,%r9
jne    11f0 <setRates+0xf0>
cmp    %rcx,%rdx
je     122d <setRates+0x12d>
movabs $0x3fe0000000000000,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,(%rdi,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1220 <setRates+0x120>
movslq %r8d,%rax
movabs $0x3ff0000000000000,%rcx
mov    %rcx,(%rdi,%rax,8)
ret

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

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