#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);
double log(double);
double pow(double, int);
double reb_random_uniform(int, int);
double reb_random_powerlaw(double min, double max, double slope) {
  double y = reb_random_uniform(0., 1.);
  if (slope == -1)
    return exp(y * log(max / min) + log(min));
  else
    return pow((pow(max, slope + 1.) - pow(min, slope + 1.)) * y +
                   pow(min, slope + 1.),
               1. / (slope + 1.));
}


x86 assembly (clang, -O0):
<reb_random_powerlaw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <reb_random_uniform@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe8b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11d1 <reb_random_powerlaw+0x91>
jp     11d1 <reb_random_powerlaw+0x91>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x38(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127e <reb_random_powerlaw+0x13e>
movsd  -0x18(%rbp),%xmm0
movsd  0xe2a(%rip),%xmm1
addsd  -0x20(%rbp),%xmm1
cvttsd2si %xmm1,%edi
call   1050 <pow@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe0a(%rip),%xmm1
addsd  -0x20(%rbp),%xmm1
cvttsd2si %xmm1,%edi
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xdd4(%rip),%xmm1
addsd  -0x20(%rbp),%xmm1
cvttsd2si %xmm1,%edi
call   1050 <pow@plt>
movsd  -0x48(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xda9(%rip),%xmm2
addsd  -0x20(%rbp),%xmm2
movsd  0xd9c(%rip),%xmm1
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%edi
call   1050 <pow@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reb_random_powerlaw>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x10(%rsp)
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <reb_random_uniform@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm1
ucomisd 0xe8a(%rip),%xmm1
jne    11b5 <reb_random_powerlaw+0x75>
jp     11b5 <reb_random_powerlaw+0x75>
movsd  (%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
call   1040 <log@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <log@plt>
movsd  0x18(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
jmp    1030 <exp@plt>
movapd %xmm1,%xmm0
addsd  0xe47(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
cvttsd2si %xmm0,%ebx
movsd  (%rsp),%xmm0
mov    %ebx,%edi
call   1050 <pow@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    %ebx,%edi
call   1050 <pow@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    %ebx,%edi
call   1050 <pow@plt>
movsd  (%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xded(%rip),%xmm1
divsd  0x8(%rsp),%xmm1
cvttsd2si %xmm1,%edi
add    $0x20,%rsp
pop    %rbx
jmp    1050 <pow@plt>

LLVM IR (-O0):
define double @reb_random_powerlaw(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%9 = call double @reb_random_uniform(i32 0, i32 1)
store double %9, double* %8
%10 = load double, double* %7
%11 = fcmp oeq double %10, -1.000000e+00
br i1 %11, label %12, label %22
12: ; preds = %3
%13 = load double, double* %8
%14 = load double, double* %6
%15 = load double, double* %5
%16 = fdiv double %14, %15
%17 = call double @log(double %16)
%18 = load double, double* %5
%19 = call double @log(double %18)
%20 = call double @llvm.fmuladd.f64(double %13, double %17, double %19)
%21 = call double @exp(double %20)
store double %21, double* %4
br label %46
22: ; preds = %3
%23 = load double, double* %6
%24 = load double, double* %7
%25 = fadd double %24, 1.000000e+00
%26 = fptosi double %25 to i32
%27 = call double @pow(double %23, i32 %26)
%28 = load double, double* %5
%29 = load double, double* %7
%30 = fadd double %29, 1.000000e+00
%31 = fptosi double %30 to i32
%32 = call double @pow(double %28, i32 %31)
%33 = fsub double %27, %32
%34 = load double, double* %8
%35 = load double, double* %5
%36 = load double, double* %7
%37 = fadd double %36, 1.000000e+00
%38 = fptosi double %37 to i32
%39 = call double @pow(double %35, i32 %38)
%40 = call double @llvm.fmuladd.f64(double %33, double %34, double %39)
%41 = load double, double* %7
%42 = fadd double %41, 1.000000e+00
%43 = fdiv double 1.000000e+00, %42
%44 = fptosi double %43 to i32
%45 = call double @pow(double %40, i32 %44)
store double %45, double* %4
br label %46
46: ; preds = %22, %12
%47 = load double, double* %4
ret double %47
}

LLVM IR (-O2):
define double @reb_random_powerlaw(double %0, double %1, double %2) {
%4 = tail call double @reb_random_uniform(i32 0, i32 1)
%5 = fcmp oeq double %2, -1.000000e+00
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = fdiv double %1, %0
%8 = tail call double @log(double %7)
%9 = tail call double @log(double %0)
%10 = tail call double @llvm.fmuladd.f64(double %4, double %8, double %9)
%11 = tail call double @exp(double %10)
br label %23
12: ; preds = %3
%13 = fadd double %2, 1.000000e+00
%14 = fptosi double %13 to i32
%15 = tail call double @pow(double %1, i32 %14)
%16 = tail call double @pow(double %0, i32 %14)
%17 = fsub double %15, %16
%18 = tail call double @pow(double %0, i32 %14)
%19 = tail call double @llvm.fmuladd.f64(double %17, double %4, double %18)
%20 = fdiv double 1.000000e+00, %13
%21 = fptosi double %20 to i32
%22 = tail call double @pow(double %19, i32 %21)
br label %23
23: ; preds = %12, %6
%24 = phi double [ %11, %6 ], [ %22, %12 ]
ret double %24
}