rnum(n) {
  static short first[2];
  if (first[1] == 0) {
    time(first);
    srand((first[1] * first[0]) ^ first[1]);
  }
  return ((rand() / 32768.0) * n);
}


x86 assembly (clang, -O0):
<rnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movswl 0x2efa(%rip),%eax
cmp    $0x0,%eax
jne    117a <rnum+0x4a>
lea    0x2ee8(%rip),%rdi
mov    $0x0,%al
call   1040 <time@plt>
movswl 0x2edc(%rip),%edi
movswl 0x2ed3(%rip),%eax
imul   %eax,%edi
movswl 0x2ecb(%rip),%eax
xor    %eax,%edi
mov    $0x0,%al
call   1030 <srand@plt>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe73(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnum>:
push   %rbx
mov    %edi,%ebx
cmpw   $0x0,0x2f01(%rip)
jne    1165 <rnum+0x35>
lea    0x2ef6(%rip),%rdi
xor    %eax,%eax
call   1040 <time@plt>
movswl 0x2eea(%rip),%eax
movswl 0x2ee1(%rip),%edi
imul   %eax,%edi
xor    %eax,%edi
xor    %eax,%eax
call   1030 <srand@plt>
xor    %eax,%eax
call   1050 <rand@plt>
cvtsi2sd %eax,%xmm0
mulsd  0xe88(%rip),%xmm0
cvtsi2sd %ebx,%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@rnum.first = internal global [2 x i16] zeroinitializer
define i32 @rnum(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 1)
%4 = sext i16 %3 to i32
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %1
%7 = call i32 (i16*, ...) bitcast (i32 (...)* @time to i32 (i16*, ...)*)(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 0))
%8 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 1)
%9 = sext i16 %8 to i32
%10 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 0)
%11 = sext i16 %10 to i32
%12 = mul nsw i32 %9, %11
%13 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 1)
%14 = sext i16 %13 to i32
%15 = xor i32 %12, %14
%16 = call i32 (i32, ...) bitcast (i32 (...)* @srand to i32 (i32, ...)*)(i32 %15)
br label %17
17: ; preds = %6, %1
%18 = call i32 (...) @rand()
%19 = sitofp i32 %18 to double
%20 = fdiv double %19, 3.276800e+04
%21 = load i32, i32* %2
%22 = sitofp i32 %21 to double
%23 = fmul double %20, %22
%24 = fptosi double %23 to i32
ret i32 %24
}

LLVM IR (-O2):
@rnum.first = internal global [2 x i16] zeroinitializer
define i32 @rnum(i32 %0) {
%2 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 1)
%3 = icmp eq i16 %2, 0
br i1 %3, label %4, label %13
4: ; preds = %1
%5 = tail call i32 (i16*, ...) bitcast (i32 (...)* @time to i32 (i16*, ...)*)(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 0))
%6 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 1)
%7 = sext i16 %6 to i32
%8 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 0)
%9 = sext i16 %8 to i32
%10 = mul nsw i32 %9, %7
%11 = xor i32 %10, %7
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @srand to i32 (i32, ...)*)(i32 %11)
br label %13
13: ; preds = %4, %1
%14 = tail call i32 (...) @rand()
%15 = sitofp i32 %14 to double
%16 = fmul double %15, 0x3F00000000000000
%17 = sitofp i32 %0 to double
%18 = fmul double %16, %17
%19 = fptosi double %18 to i32
ret i32 %19
}