#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 */
double drand();
double sqrt(int);
void create_vsrp(double *X, int M, int Mp) {
  int j;
  double r;
  double tmp1 = 1.0 / (2.0 * sqrt(M));
  for (j = 0; j < M * Mp; j++) {
    r = drand();
    if (r < tmp1)
      X[j] = -1;
    else if (r >= tmp1)
      X[j] = 1;
    else
      X[j] = 0;
  }
}


x86 assembly (clang, -O0):
<create_vsrp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <sqrt@plt>
movsd  0xec6(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xeb2(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    11fc <create_vsrp+0xdc>
mov    $0x0,%al
call   1030 <drand@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11aa <create_vsrp+0x8a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  0xe70(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11e9 <create_vsrp+0xc9>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     11d4 <create_vsrp+0xb4>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  0xe36(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11e4 <create_vsrp+0xc4>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11e9 <create_vsrp+0xc9>
jmp    11ee <create_vsrp+0xce>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <create_vsrp+0x3e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_vsrp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r12
mov    %esi,%edi
call   1040 <sqrt@plt>
imul   %r14d,%ebp
test   %ebp,%ebp
jle    11b6 <create_vsrp+0x96>
addsd  %xmm0,%xmm0
movsd  0xeb1(%rip),%xmm1
divsd  %xmm0,%xmm1
mov    %ebp,%ebp
movabs $0xbff0000000000000,%r14
movabs $0x3ff0000000000000,%r15
xor    %ebx,%ebx
movsd  %xmm1,0x8(%rsp)
jmp    118d <create_vsrp+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11b6 <create_vsrp+0x96>
xor    %eax,%eax
call   1030 <drand@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1180 <create_vsrp+0x60>
ucomisd %xmm1,%xmm0
jae    11b0 <create_vsrp+0x90>
movq   $0x0,(%r12,%rbx,8)
jmp    1184 <create_vsrp+0x64>
mov    %r15,(%r12,%rbx,8)
jmp    1184 <create_vsrp+0x64>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @create_vsrp(double* %0, i32 %1, i32 %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = call double @sqrt(i32 %10)
%12 = fmul double 2.000000e+00, %11
%13 = fdiv double 1.000000e+00, %12
store double %13, double* %9
store i32 0, i32* %7
br label %14
14: ; preds = %46, %3
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = mul nsw i32 %16, %17
%19 = icmp slt i32 %15, %18
br i1 %19, label %20, label %49
20: ; preds = %14
%21 = call double (...) @drand()
store double %21, double* %8
%22 = load double, double* %8
%23 = load double, double* %9
%24 = fcmp olt double %22, %23
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load double*, double** %4
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
store double -1.000000e+00, double* %29
br label %45
30: ; preds = %20
%31 = load double, double* %8
%32 = load double, double* %9
%33 = fcmp oge double %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load double*, double** %4
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
store double 1.000000e+00, double* %38
br label %44
39: ; preds = %30
%40 = load double*, double** %4
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
store double 0.000000e+00, double* %43
br label %44
44: ; preds = %39, %34
br label %45
45: ; preds = %44, %25
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %14
49: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @create_vsrp(double* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = tail call double @sqrt(i32 %1)
%5 = fmul double %4, 2.000000e+00
%6 = fdiv double 1.000000e+00, %5
%7 = mul i32 %2, %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %3
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %22
%12 = phi i64 [ 0, %9 ], [ %23, %22 ]
%13 = tail call double (...) @drand()
%14 = fcmp olt double %13, %6
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = getelementptr inbounds double, double* %0, i64 %12
store double -1.000000e+00, double* %16
br label %22
17: ; preds = %11
%18 = fcmp ult double %13, %6
%19 = getelementptr inbounds double, double* %0, i64 %12
br i1 %18, label %21, label %20
20: ; preds = %17
store double 1.000000e+00, double* %19
br label %22
21: ; preds = %17
store double 0.000000e+00, double* %19
br label %22
22: ; preds = %15, %21, %20
%23 = add nuw nsw i64 %12, 1
%24 = icmp eq i64 %23, %10
br i1 %24, label %25, label %11
25: ; preds = %22, %3
ret void
}