#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 exp(double);
int /*<<< orphan*/ getRandomDouble(double, double);
double log(int /*<<< orphan*/);
void setRandomDistribution(double *x, int num_probs) {
  int i, j;
  x[0] = 1.0;
  for (i = 1; i < num_probs; i++) {
    x[i] = 1.0 - exp(1.0 / i * log(getRandomDouble(0.0, 1.0)));
    for (j = 0; j < i; j++)
      x[j] *= 1.0 - x[i];
  }
}


x86 assembly (clang, -O0):
<setRandomDistribution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xeb5(%rip),%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1217 <setRandomDistribution+0xe7>
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xe91(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  0xe7d(%rip),%xmm1
call   1030 <getRandomDouble@plt>
mov    %eax,%edi
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xe55(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1204 <setRandomDistribution+0xd4>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  0xe21(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c3 <setRandomDistribution+0x93>
jmp    1209 <setRandomDistribution+0xd9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <setRandomDistribution+0x26>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setRandomDistribution>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rdi)
cmp    $0x2,%esi
jl     125f <setRandomDistribution+0x12f>
mov    %rdi,%rbx
mov    %esi,%r14d
mov    $0x1,%r15d
xor    %r12d,%r12d
movsd  0xe9b(%rip),%xmm1
jmp    1181 <setRandomDistribution+0x51>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
add    $0x1,%r12
cmp    %r14,%r15
je     125f <setRandomDistribution+0x12f>
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movapd %xmm1,%xmm2
divsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
xorpd  %xmm0,%xmm0
call   1030 <getRandomDouble@plt>
mov    %eax,%edi
call   1050 <log@plt>
mulsd  (%rsp),%xmm0
call   1040 <exp@plt>
movsd  0xe48(%rip),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
movsd  %xmm2,(%rbx,%r15,8)
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
mulsd  (%rbx),%xmm0
movsd  %xmm0,(%rbx)
cmp    $0x1,%r15
je     1170 <setRandomDistribution+0x40>
mov    $0x1,%eax
cmp    $0x1,%r12
je     123c <setRandomDistribution+0x10c>
mov    %r12,%rcx
and    $0xfffffffffffffffe,%rcx
neg    %rcx
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
movapd %xmm1,%xmm0
subsd  (%rbx,%r15,8),%xmm0
mulsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
movapd %xmm1,%xmm0
subsd  (%rbx,%r15,8),%xmm0
mulsd  0x8(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rax,8)
lea    (%rcx,%rax,1),%rdx
add    $0x2,%rdx
add    $0x2,%rax
cmp    $0x1,%rdx
jne    1200 <setRandomDistribution+0xd0>
test   $0x1,%r12b
je     1170 <setRandomDistribution+0x40>
movapd %xmm1,%xmm0
subsd  (%rbx,%r15,8),%xmm0
mulsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
jmp    1170 <setRandomDistribution+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @setRandomDistribution(double* nocapture %0, i32 %1) {
store double 1.000000e+00, double* %0
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %57
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %53
%7 = phi i64 [ 0, %4 ], [ %56, %53 ]
%8 = phi i64 [ 1, %4 ], [ %54, %53 ]
%9 = trunc i64 %8 to i32
%10 = sitofp i32 %9 to double
%11 = fdiv double 1.000000e+00, %10
%12 = tail call i32 @getRandomDouble(double 0.000000e+00, double 1.000000e+00)
%13 = tail call double @log(i32 %12)
%14 = fmul double %11, %13
%15 = tail call double @exp(double %14)
%16 = fsub double 1.000000e+00, %15
%17 = getelementptr inbounds double, double* %0, i64 %8
store double %16, double* %17
%18 = fsub double 1.000000e+00, %16
%19 = load double, double* %0
%20 = fmul double %19, %18
store double %20, double* %0
%21 = icmp eq i64 %8, 1
br i1 %21, label %53, label %22
22: ; preds = %6
%23 = and i64 %7, 1
%24 = icmp eq i64 %7, 1
br i1 %24, label %44, label %25
25: ; preds = %22
%26 = and i64 %7, -2
br label %27
27: ; preds = %27, %25
%28 = phi i64 [ 1, %25 ], [ %41, %27 ]
%29 = phi i64 [ 0, %25 ], [ %42, %27 ]
%30 = load double, double* %17
%31 = fsub double 1.000000e+00, %30
%32 = getelementptr inbounds double, double* %0, i64 %28
%33 = load double, double* %32
%34 = fmul double %33, %31
store double %34, double* %32
%35 = add nuw nsw i64 %28, 1
%36 = load double, double* %17
%37 = fsub double 1.000000e+00, %36
%38 = getelementptr inbounds double, double* %0, i64 %35
%39 = load double, double* %38
%40 = fmul double %39, %37
store double %40, double* %38
%41 = add nuw nsw i64 %28, 2
%42 = add i64 %29, 2
%43 = icmp eq i64 %42, %26
br i1 %43, label %44, label %27
44: ; preds = %27, %22
%45 = phi i64 [ 1, %22 ], [ %41, %27 ]
%46 = icmp eq i64 %23, 0
br i1 %46, label %53, label %47
47: ; preds = %44
%48 = load double, double* %17
%49 = fsub double 1.000000e+00, %48
%50 = getelementptr inbounds double, double* %0, i64 %45
%51 = load double, double* %50
%52 = fmul double %51, %49
store double %52, double* %50
br label %53
53: ; preds = %47, %44, %6
%54 = add nuw nsw i64 %8, 1
%55 = icmp eq i64 %54, %5
%56 = add i64 %7, 1
br i1 %55, label %57, label %6
57: ; preds = %53, %2
ret void
}