#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*/ assert(double *);
scalar_t__ malloc(unsigned int);
double pow(unsigned int, double);
double *gen_zipf_lut(double zipf_factor, unsigned int alphabet_size) {
  double scaling_factor;
  double sum;
  double *lut;
  lut = (double *)malloc(alphabet_size * sizeof(*lut));
  assert(lut);
  scaling_factor = 0.0;
  for (unsigned int i = 1; i <= alphabet_size; i++)
    scaling_factor += 1.0 / pow(i, zipf_factor);
  sum = 0.0;
  for (unsigned int i = 1; i <= alphabet_size; i++) {
    sum += 1.0 / pow(i, zipf_factor);
    lut[i - 1] = sum / scaling_factor;
  }
  return lut;
}


x86 assembly (clang, -O0):
<gen_zipf_lut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <assert@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     11aa <gen_zipf_lut+0x7a>
mov    -0x2c(%rbp),%edi
movsd  -0x8(%rbp),%xmm0
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe72(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116a <gen_zipf_lut+0x3a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     1214 <gen_zipf_lut+0xe4>
mov    -0x30(%rbp),%edi
movsd  -0x8(%rbp),%xmm0
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe23(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11b9 <gen_zipf_lut+0x89>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_zipf_lut>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r15d
movsd  %xmm0,0x18(%rsp)
lea    0x0(,%r15,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <assert@plt>
test   %r15d,%r15d
je     1210 <gen_zipf_lut+0xe0>
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
movsd  0x18(%rsp),%xmm0
call   1050 <pow@plt>
movsd  0xe75(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%ebx
cmp    %r15d,%ebx
jbe    1170 <gen_zipf_lut+0x40>
test   %r15d,%r15d
je     1210 <gen_zipf_lut+0xe0>
xorpd  %xmm1,%xmm1
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
mov    %ebx,%edi
movsd  0x18(%rsp),%xmm0
call   1050 <pow@plt>
movsd  0xe25(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
divsd  0x8(%rsp),%xmm0
lea    -0x1(%rbx),%eax
movsd  %xmm0,(%r14,%rax,8)
add    $0x1,%ebx
cmp    %r15d,%ebx
jbe    11c0 <gen_zipf_lut+0x90>
mov    %r14,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @gen_zipf_lut(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = zext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %7
%16 = load double*, double** %7
%17 = call i32 @assert(double* %16)
store double 0.000000e+00, double* %5
store i32 1, i32* %8
br label %18
18: ; preds = %29, %2
%19 = load i32, i32* %8
%20 = load i32, i32* %4
%21 = icmp ule i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %8
%24 = load double, double* %3
%25 = call double @pow(i32 %23, double %24)
%26 = fdiv double 1.000000e+00, %25
%27 = load double, double* %5
%28 = fadd double %27, %26
store double %28, double* %5
br label %29
29: ; preds = %22
%30 = load i32, i32* %8
%31 = add i32 %30, 1
store i32 %31, i32* %8
br label %18
32: ; preds = %18
store double 0.000000e+00, double* %6
store i32 1, i32* %9
br label %33
33: ; preds = %52, %32
%34 = load i32, i32* %9
%35 = load i32, i32* %4
%36 = icmp ule i32 %34, %35
br i1 %36, label %37, label %55
37: ; preds = %33
%38 = load i32, i32* %9
%39 = load double, double* %3
%40 = call double @pow(i32 %38, double %39)
%41 = fdiv double 1.000000e+00, %40
%42 = load double, double* %6
%43 = fadd double %42, %41
store double %43, double* %6
%44 = load double, double* %6
%45 = load double, double* %5
%46 = fdiv double %44, %45
%47 = load double*, double** %7
%48 = load i32, i32* %9
%49 = sub i32 %48, 1
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds double, double* %47, i64 %50
store double %46, double* %51
br label %52
52: ; preds = %37
%53 = load i32, i32* %9
%54 = add i32 %53, 1
store i32 %54, i32* %9
br label %33
55: ; preds = %33
%56 = load double*, double** %7
ret double* %56
}

LLVM IR (-O2):
define double* @gen_zipf_lut(double %0, i32 %1) {
%3 = shl i32 %1, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double*
%6 = tail call i32 @assert(double* %5)
%7 = icmp eq i32 %1, 0
br i1 %7, label %17, label %9
8: ; preds = %9
br i1 %7, label %17, label %18
9: ; preds = %2, %9
%10 = phi i32 [ %15, %9 ], [ 1, %2 ]
%11 = phi double [ %14, %9 ], [ 0.000000e+00, %2 ]
%12 = tail call double @pow(i32 %10, double %0)
%13 = fdiv double 1.000000e+00, %12
%14 = fadd double %11, %13
%15 = add i32 %10, 1
%16 = icmp ugt i32 %15, %1
br i1 %16, label %8, label %9
17: ; preds = %18, %2, %8
ret double* %5
18: ; preds = %8, %18
%19 = phi i32 [ %28, %18 ], [ 1, %8 ]
%20 = phi double [ %23, %18 ], [ 0.000000e+00, %8 ]
%21 = tail call double @pow(i32 %19, double %0)
%22 = fdiv double 1.000000e+00, %21
%23 = fadd double %20, %22
%24 = fdiv double %23, %14
%25 = add i32 %19, -1
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds double, double* %5, i64 %26
store double %24, double* %27
%28 = add i32 %19, 1
%29 = icmp ugt i32 %28, %1
br i1 %29, label %17, label %18
}