int rnum(n) {
  static short first[2];
  if (first[1] == 0) {
    time(first);
    if (first[1] == 0)
      first[1] = 1;
    srand((first[1] * first[0]) ^ first[1]);
  }
  return ((int)((rand() / 2147483648.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    1193 <rnum+0x63>
lea    0x2ee8(%rip),%rdi
mov    $0x0,%al
call   1040 <time@plt>
movswl 0x2edc(%rip),%eax
cmp    $0x0,%eax
jne    1172 <rnum+0x42>
movw   $0x1,0x2eca(%rip)
movswl 0x2ec3(%rip),%edi
movswl 0x2eba(%rip),%eax
imul   %eax,%edi
movswl 0x2eb2(%rip),%eax
xor    %eax,%edi
mov    $0x0,%al
call   1030 <srand@plt>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe5a(%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    1178 <rnum+0x48>
lea    0x2ef6(%rip),%rdi
xor    %eax,%eax
call   1040 <time@plt>
movzwl 0x2eea(%rip),%eax
test   %ax,%ax
jne    1164 <rnum+0x34>
movw   $0x1,0x2edc(%rip)
mov    $0x1,%ax
cwtl
movswl 0x2ece(%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  0xe75(%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 %22
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 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %6
store i16 1, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 1)
br label %12
12: ; preds = %11, %6
%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 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 0)
%16 = sext i16 %15 to i32
%17 = mul nsw i32 %14, %16
%18 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 1)
%19 = sext i16 %18 to i32
%20 = xor i32 %17, %19
%21 = call i32 (i32, ...) bitcast (i32 (...)* @srand to i32 (i32, ...)*)(i32 %20)
br label %22
22: ; preds = %12, %1
%23 = call i32 (...) @rand()
%24 = sitofp i32 %23 to double
%25 = fdiv double %24, 0x41E0000000000000
%26 = load i32, i32* %2
%27 = sitofp i32 %26 to double
%28 = fmul double %25, %27
%29 = fptosi double %28 to i32
ret i32 %29
}

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 %17
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 = icmp eq i16 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %4
store i16 1, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 1)
br label %9
9: ; preds = %8, %4
%10 = phi i16 [ 1, %8 ], [ %6, %4 ]
%11 = sext i16 %10 to i32
%12 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @rnum.first, i64 0, i64 0)
%13 = sext i16 %12 to i32
%14 = mul nsw i32 %13, %11
%15 = xor i32 %14, %11
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @srand to i32 (i32, ...)*)(i32 %15)
br label %17
17: ; preds = %9, %1
%18 = tail call i32 (...) @rand()
%19 = sitofp i32 %18 to double
%20 = fmul double %19, 0x3E00000000000000
%21 = sitofp i32 %0 to double
%22 = fmul double %20, %21
%23 = fptosi double %22 to i32
ret i32 %23
}