#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 */
int /*<<< orphan*/ ddrand(int, double *, int, int *);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
void randomdens(int n, double *x, double r1, double r2, double densty,
                int *seeds) {
  int i;
  double *y;
  y = (double *)malloc(sizeof(*y) * (n + 1));
  ddrand(n, x, 1, seeds);
  ddrand(n, y, 1, seeds);
  for (i = 1; i <= n; i++) {
    if (y[i] < densty)
      x[i] = r1 + (r2 - r1) * x[i];
    else
      x[i] = 0.0;
  }
  free(y);
}


x86 assembly (clang, -O0):
<randomdens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1040 <ddrand@plt>
mov    -0x4(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1040 <ddrand@plt>
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     121b <randomdens+0xeb>
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f8 <randomdens+0xc8>
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1208 <randomdens+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    120d <randomdens+0xdd>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119a <randomdens+0x6a>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomdens>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
mov    %rsi,%rbx
mov    %edi,%r15d
lea    0x8(,%r15,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <ddrand@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <ddrand@plt>
movsd  0x10(%rsp),%xmm4
test   %r15d,%r15d
jle    11d7 <randomdens+0xa7>
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm3
subsd  %xmm3,%xmm2
mov    %r15d,%ecx
mov    $0x1,%eax
cmp    $0x1,%r15d
jne    11ea <randomdens+0xba>
test   $0x1,%cl
je     11d7 <randomdens+0xa7>
xorpd  %xmm0,%xmm0
ucomisd (%r14,%rax,8),%xmm4
jbe    11d2 <randomdens+0xa2>
movapd %xmm2,%xmm0
mulsd  (%rbx,%rax,8),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
mov    %r14,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    %ecx,%edx
and    $0xfffffffe,%edx
neg    %rdx
mov    $0x1,%eax
jmp    1218 <randomdens+0xe8>
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rbx,%rax,8)
lea    (%rdx,%rax,1),%rsi
add    $0x2,%rsi
add    $0x2,%rax
cmp    $0x1,%rsi
je     11b3 <randomdens+0x83>
xorpd  %xmm0,%xmm0
ucomisd (%r14,%rax,8),%xmm4
xorpd  %xmm1,%xmm1
jbe    1235 <randomdens+0x105>
movsd  (%rbx,%rax,8),%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm3,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
ucomisd 0x8(%r14,%rax,8),%xmm4
jbe    1200 <randomdens+0xd0>
movsd  0x8(%rbx,%rax,8),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
jmp    1200 <randomdens+0xd0>

LLVM IR (-O0):
define void @randomdens(i32 %0, double* %1, double %2, double %3, double %4, i32* %5) {
%7 = alloca i32
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32*
%13 = alloca i32
%14 = alloca double*
store i32 %0, i32* %7
store double* %1, double** %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
store i32* %5, i32** %12
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 8, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to double*
store double* %21, double** %14
%22 = load i32, i32* %7
%23 = load double*, double** %8
%24 = load i32*, i32** %12
%25 = call i32 @ddrand(i32 %22, double* %23, i32 1, i32* %24)
%26 = load i32, i32* %7
%27 = load double*, double** %14
%28 = load i32*, i32** %12
%29 = call i32 @ddrand(i32 %26, double* %27, i32 1, i32* %28)
store i32 1, i32* %13
br label %30
30: ; preds = %63, %6
%31 = load i32, i32* %13
%32 = load i32, i32* %7
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %66
34: ; preds = %30
%35 = load double*, double** %14
%36 = load i32, i32* %13
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load double, double* %11
%41 = fcmp olt double %39, %40
br i1 %41, label %42, label %57
42: ; preds = %34
%43 = load double, double* %9
%44 = load double, double* %10
%45 = load double, double* %9
%46 = fsub double %44, %45
%47 = load double*, double** %8
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = call double @llvm.fmuladd.f64(double %46, double %51, double %43)
%53 = load double*, double** %8
%54 = load i32, i32* %13
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
store double %52, double* %56
br label %62
57: ; preds = %34
%58 = load double*, double** %8
%59 = load i32, i32* %13
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
store double 0.000000e+00, double* %61
br label %62
62: ; preds = %57, %42
br label %63
63: ; preds = %62
%64 = load i32, i32* %13
%65 = add nsw i32 %64, 1
store i32 %65, i32* %13
br label %30
66: ; preds = %30
%67 = load double*, double** %14
%68 = call i32 @free(double* %67)
ret void
}

LLVM IR (-O2):
define void @randomdens(i32 %0, double* %1, double %2, double %3, double %4, i32* %5) {
%7 = shl i32 %0, 3
%8 = add i32 %7, 8
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to double*
%11 = tail call i32 @ddrand(i32 %0, double* %1, i32 1, i32* %5)
%12 = tail call i32 @ddrand(i32 %0, double* %10, i32 1, i32* %5)
%13 = icmp slt i32 %0, 1
br i1 %13, label %59, label %14
14: ; preds = %6
%15 = fsub double %3, %2
%16 = zext i32 %0 to i64
%17 = and i64 %16, 1
%18 = icmp eq i32 %0, 1
br i1 %18, label %46, label %19
19: ; preds = %14
%20 = and i64 %16, 4294967294
br label %21
21: ; preds = %41, %19
%22 = phi i64 [ 1, %19 ], [ %43, %41 ]
%23 = phi i64 [ 0, %19 ], [ %44, %41 ]
%24 = getelementptr inbounds double, double* %10, i64 %22
%25 = load double, double* %24
%26 = fcmp olt double %25, %4
%27 = getelementptr inbounds double, double* %1, i64 %22
br i1 %26, label %28, label %31
28: ; preds = %21
%29 = load double, double* %27
%30 = tail call double @llvm.fmuladd.f64(double %15, double %29, double %2)
br label %31
31: ; preds = %21, %28
%32 = phi double [ %30, %28 ], [ 0.000000e+00, %21 ]
store double %32, double* %27
%33 = add nuw nsw i64 %22, 1
%34 = getelementptr inbounds double, double* %10, i64 %33
%35 = load double, double* %34
%36 = fcmp olt double %35, %4
%37 = getelementptr inbounds double, double* %1, i64 %33
br i1 %36, label %38, label %41
38: ; preds = %31
%39 = load double, double* %37
%40 = tail call double @llvm.fmuladd.f64(double %15, double %39, double %2)
br label %41
41: ; preds = %38, %31
%42 = phi double [ %40, %38 ], [ 0.000000e+00, %31 ]
store double %42, double* %37
%43 = add nuw nsw i64 %22, 2
%44 = add i64 %23, 2
%45 = icmp eq i64 %44, %20
br i1 %45, label %46, label %21
46: ; preds = %41, %14
%47 = phi i64 [ 1, %14 ], [ %43, %41 ]
%48 = icmp eq i64 %17, 0
br i1 %48, label %59, label %49
49: ; preds = %46
%50 = getelementptr inbounds double, double* %10, i64 %47
%51 = load double, double* %50
%52 = fcmp olt double %51, %4
%53 = getelementptr inbounds double, double* %1, i64 %47
br i1 %52, label %54, label %57
54: ; preds = %49
%55 = load double, double* %53
%56 = tail call double @llvm.fmuladd.f64(double %15, double %55, double %2)
br label %57
57: ; preds = %54, %49
%58 = phi double [ %56, %54 ], [ 0.000000e+00, %49 ]
store double %58, double* %53
br label %59
59: ; preds = %57, %46, %6
%60 = tail call i32 @free(double* %10)
ret void
}