#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 RAND_MAX;
double pow(double, double);
scalar_t__ rand();
long long powerLawRand(long long min, long long max, double alpha) {
  double pl, r;
  max += 1;
  r = ((double)rand()) / RAND_MAX;
  pl = pow(
      ((pow(max, alpha + 1) - pow(min, alpha + 1)) * r + pow(min, alpha + 1)),
      (1.0 / (alpha + 1)));
  return (max - 1 - (long long)pl) + min;
}


x86 assembly (clang, -O0):
<powerLawRand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e94(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe95(%rip),%xmm1
addsd  -0x18(%rbp),%xmm1
call   1030 <pow@plt>
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe78(%rip),%xmm1
addsd  -0x18(%rbp),%xmm1
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe45(%rip),%xmm1
addsd  -0x18(%rbp),%xmm1
call   1030 <pow@plt>
movsd  -0x38(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe1e(%rip),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  0xe11(%rip),%xmm1
divsd  %xmm2,%xmm1
call   1030 <pow@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
cvttsd2si -0x20(%rbp),%rcx
sub    %rcx,%rax
add    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<powerLawRand>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x1(%rsi),%r15
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e9a(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,0x18(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r15,%xmm0
movsd  (%rsp),%xmm1
addsd  0xe93(%rip),%xmm1
movsd  %xmm1,(%rsp)
call   1030 <pow@plt>
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r14,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm1
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x18(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1030 <pow@plt>
addsd  0x8(%rsp),%xmm0
movsd  0xe37(%rip),%xmm1
divsd  (%rsp),%xmm1
call   1030 <pow@plt>
cvttsd2si %xmm0,%rax
add    %r14,%rbx
sub    %rax,%rbx
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i64 @powerLawRand(i64 %0, i64 %1, double %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i64 %0, i64* %4
store i64 %1, i64* %5
store double %2, double* %6
%9 = load i64, i64* %5
%10 = add nsw i64 %9, 1
store i64 %10, i64* %5
%11 = call i64 (...) @rand()
%12 = sitofp i64 %11 to double
%13 = load double, double* @RAND_MAX
%14 = fdiv double %12, %13
store double %14, double* %8
%15 = load i64, i64* %5
%16 = sitofp i64 %15 to double
%17 = load double, double* %6
%18 = fadd double %17, 1.000000e+00
%19 = call double @pow(double %16, double %18)
%20 = load i64, i64* %4
%21 = sitofp i64 %20 to double
%22 = load double, double* %6
%23 = fadd double %22, 1.000000e+00
%24 = call double @pow(double %21, double %23)
%25 = fsub double %19, %24
%26 = load double, double* %8
%27 = load i64, i64* %4
%28 = sitofp i64 %27 to double
%29 = load double, double* %6
%30 = fadd double %29, 1.000000e+00
%31 = call double @pow(double %28, double %30)
%32 = call double @llvm.fmuladd.f64(double %25, double %26, double %31)
%33 = load double, double* %6
%34 = fadd double %33, 1.000000e+00
%35 = fdiv double 1.000000e+00, %34
%36 = call double @pow(double %32, double %35)
store double %36, double* %7
%37 = load i64, i64* %5
%38 = sub nsw i64 %37, 1
%39 = load double, double* %7
%40 = fptosi double %39 to i64
%41 = sub nsw i64 %38, %40
%42 = load i64, i64* %4
%43 = add nsw i64 %41, %42
ret i64 %43
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i64 @powerLawRand(i64 %0, i64 %1, double %2) {
%4 = add nsw i64 %1, 1
%5 = tail call i64 (...) @rand()
%6 = sitofp i64 %5 to double
%7 = load double, double* @RAND_MAX
%8 = fdiv double %6, %7
%9 = sitofp i64 %4 to double
%10 = fadd double %2, 1.000000e+00
%11 = tail call double @pow(double %9, double %10)
%12 = sitofp i64 %0 to double
%13 = tail call double @pow(double %12, double %10)
%14 = fsub double %11, %13
%15 = tail call double @pow(double %12, double %10)
%16 = tail call double @llvm.fmuladd.f64(double %14, double %8, double %15)
%17 = fdiv double 1.000000e+00, %10
%18 = tail call double @pow(double %16, double %17)
%19 = fptosi double %18 to i64
%20 = add i64 %1, %0
%21 = sub i64 %20, %19
ret i64 %21
}