#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 */

/* Variables and functions */
scalar_t__ RAND_MAX;
scalar_t__ rand();
int /*<<< orphan*/ srand(int);
void SampleReplace(int k, int n, int *y, int seed) {
  int i;
  (srand((seed)));
  for (i = 0; i < k; i++)
    y[i] = n * (((float)rand()) / ((float)RAND_MAX));
}


x86 assembly (clang, -O0):
<SampleReplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <srand@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119c <SampleReplace+0x7c>
cvtsi2ssl -0x8(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movss  -0x1c(%rbp),%xmm0
cvtsi2ss %rax,%xmm1
mov    0x2e76(%rip),%rax
cvtsi2ssq (%rax),%xmm2
divss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1144 <SampleReplace+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SampleReplace>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %edi,%ebp
mov    %ecx,%edi
call   1030 <srand@plt>
test   %ebp,%ebp
jle    1182 <SampleReplace+0x62>
cvtsi2ss %r14d,%xmm0
movss  %xmm0,0x4(%rsp)
mov    %ebp,%ebp
mov    0x2e9a(%rip),%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq (%r14),%xmm1
divss  %xmm1,%xmm0
mulss  0x4(%rsp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <SampleReplace+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define void @SampleReplace(i32 %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
%11 = call i32 @srand(i32 %10)
store i32 0, i32* %9
br label %12
12: ; preds = %30, %4
%13 = load i32, i32* %9
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = load i32, i32* %6
%18 = sitofp i32 %17 to float
%19 = call i64 (...) @rand()
%20 = sitofp i64 %19 to float
%21 = load i64, i64* @RAND_MAX
%22 = sitofp i64 %21 to float
%23 = fdiv float %20, %22
%24 = fmul float %18, %23
%25 = fptosi float %24 to i32
%26 = load i32*, i32** %7
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
store i32 %25, i32* %29
br label %30
30: ; preds = %16
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %12
33: ; preds = %12
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define void @SampleReplace(i32 %0, i32 %1, i32* nocapture writeonly %2, i32 %3) {
%5 = tail call i32 @srand(i32 %3)
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = sitofp i32 %1 to float
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %20, %10 ]
%12 = tail call i64 (...) @rand()
%13 = sitofp i64 %12 to float
%14 = load i64, i64* @RAND_MAX
%15 = sitofp i64 %14 to float
%16 = fdiv float %13, %15
%17 = fmul float %16, %8
%18 = fptosi float %17 to i32
%19 = getelementptr inbounds i32, i32* %2, i64 %11
store i32 %18, i32* %19
%20 = add nuw nsw i64 %11, 1
%21 = icmp eq i64 %20, %9
br i1 %21, label %22, label %10
22: ; preds = %10, %4
ret void
}