float randf(float *oldval, float factor) {
  float ccrandom(), range, xlowb, upb, temp;
  range = 2.0 - (2.0 * factor);
  xlowb = *oldval - range;
  if (xlowb < -1.)
    xlowb = -1;
  upb = *oldval + range;
  if (upb > 1)
    upb = 1;
  temp = xlowb + (upb - xlowb) * ((ccrandom(*oldval) + 1) * .5);
  *oldval = temp;
  return (temp);
}


x86 assembly (clang, -O0):
<randf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
addsd  %xmm1,%xmm1
movsd  0xed2(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
subss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe9a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    117d <randf+0x6d>
movss  0xea0(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  0xe80(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    11b2 <randf+0xa2>
movss  0xe6f(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movss  -0x18(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
call   1030 <ccrandom@plt>
movsd  -0x30(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
movss  0xe21(%rip),%xmm3
addss  %xmm3,%xmm2
cvtss2sd %xmm2,%xmm2
movsd  0xe05(%rip),%xmm3
mulsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x1c(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randf>:
push   %rbx
sub    $0x10,%rsp
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movsd  0xedb(%rip),%xmm1
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
mov    %rdi,%rbx
movss  (%rdi),%xmm1
movaps %xmm1,%xmm2
subss  %xmm0,%xmm2
movss  0xeca(%rip),%xmm3
maxss  %xmm2,%xmm3
addss  %xmm1,%xmm0
movss  0xebe(%rip),%xmm2
minss  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
movsd  %xmm0,0x8(%rsp)
subss  %xmm3,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
movsd  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mov    $0x1,%al
call   1030 <ccrandom@plt>
addss  0xe87(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe6f(%rip),%xmm0
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @randf(float* %0, float %1) {
%3 = alloca float*
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store float* %0, float** %3
store float %1, float* %4
%9 = load float, float* %4
%10 = fpext float %9 to double
%11 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %10, double 2.000000e+00)
%12 = fptrunc double %11 to float
store float %12, float* %5
%13 = load float*, float** %3
%14 = load float, float* %13
%15 = load float, float* %5
%16 = fsub float %14, %15
store float %16, float* %6
%17 = load float, float* %6
%18 = fpext float %17 to double
%19 = fcmp olt double %18, -1.000000e+00
br i1 %19, label %20, label %21
20: ; preds = %2
store float -1.000000e+00, float* %6
br label %21
21: ; preds = %20, %2
%22 = load float*, float** %3
%23 = load float, float* %22
%24 = load float, float* %5
%25 = fadd float %23, %24
store float %25, float* %7
%26 = load float, float* %7
%27 = fcmp ogt float %26, 1.000000e+00
br i1 %27, label %28, label %29
28: ; preds = %21
store float 1.000000e+00, float* %7
br label %29
29: ; preds = %28, %21
%30 = load float, float* %6
%31 = fpext float %30 to double
%32 = load float, float* %7
%33 = load float, float* %6
%34 = fsub float %32, %33
%35 = fpext float %34 to double
%36 = load float*, float** %3
%37 = load float, float* %36
%38 = fpext float %37 to double
%39 = call float (double, ...) bitcast (float (...)* @ccrandom to float (double, ...)*)(double %38)
%40 = fadd float %39, 1.000000e+00
%41 = fpext float %40 to double
%42 = fmul double %41, 5.000000e-01
%43 = call double @llvm.fmuladd.f64(double %35, double %42, double %31)
%44 = fptrunc double %43 to float
store float %44, float* %8
%45 = load float, float* %8
%46 = load float*, float** %3
store float %45, float* %46
%47 = load float, float* %8
ret float %47
}

LLVM IR (-O2):
define float @randf(float* nocapture %0, float %1) {
%3 = fpext float %1 to double
%4 = tail call double @llvm.fmuladd.f64(double %3, double -2.000000e+00, double 2.000000e+00)
%5 = fptrunc double %4 to float
%6 = load float, float* %0
%7 = fsub float %6, %5
%8 = fcmp olt float %7, -1.000000e+00
%9 = select i1 %8, float -1.000000e+00, float %7
%10 = fadd float %6, %5
%11 = fcmp ogt float %10, 1.000000e+00
%12 = select i1 %11, float 1.000000e+00, float %10
%13 = fpext float %9 to double
%14 = fsub float %12, %9
%15 = fpext float %14 to double
%16 = fpext float %6 to double
%17 = tail call float (double, ...) bitcast (float (...)* @ccrandom to float (double, ...)*)(double %16)
%18 = fadd float %17, 1.000000e+00
%19 = fpext float %18 to double
%20 = fmul double %19, 5.000000e-01
%21 = tail call double @llvm.fmuladd.f64(double %15, double %20, double %13)
%22 = fptrunc double %21 to float
store float %22, float* %0
ret float %22
}