#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct timeval {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
scalar_t__ RAND_MAX;
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double);
int random();
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int main() {
  struct timeval tv;
  int i;
  int r;
  double rd;
  gettimeofday(&tv, 0);
  srandom(tv.tv_sec);
  for (i = 0; i < 100; i++) {
    r = random();
    rd = r / ((double)RAND_MAX + 1);
    printf("%f\n", rd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    -0x8(%rbp),%edi
call   1030 <srandom@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    11c2 <main+0x82>
mov    $0x0,%al
call   1060 <random@plt>
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
mov    0x2e5f(%rip),%rax
cvtsi2sdq (%rax),%xmm1
movsd  0xe6a(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1169 <main+0x29>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x8(%rsp),%edi
call   1030 <srandom@plt>
mov    $0x64,%ebp
mov    0x2e7f(%rip),%r14
lea    0xe98(%rip),%rbx
xor    %eax,%eax
call   1060 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
addsd  0xe72(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    %rbx,%rdi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1170 <main+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@RAND_MAX = global i64 0
@.str = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 0, i32* %1
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @srandom(i32 %8)
store i32 0, i32* %3
br label %10
10: ; preds = %23, %0
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 100
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = call i32 (...) @random()
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = sitofp i32 %15 to double
%17 = load i64, i64* @RAND_MAX
%18 = sitofp i64 %17 to double
%19 = fadd double %18, 1.000000e+00
%20 = fdiv double %16, %19
store double %20, double* %5
%21 = load double, double* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %21)
br label %23
23: ; preds = %13
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %10
26: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@RAND_MAX = global i64 0
@.str = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = call i32 @srandom(i32 %5)
br label %7
7: ; preds = %0, %7
%8 = phi i32 [ 0, %0 ], [ %16, %7 ]
%9 = call i32 (...) @random()
%10 = sitofp i32 %9 to double
%11 = load i64, i64* @RAND_MAX
%12 = sitofp i64 %11 to double
%13 = fadd double %12, 1.000000e+00
%14 = fdiv double %10, %13
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %14)
%16 = add nuw nsw i32 %8, 1
%17 = icmp eq i32 %16, 100
br i1 %17, label %18, label %7
18: ; preds = %7
ret i32 0
}