#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 qlnorm(double, double const, double const);
void lognormal_discretize(const double logmu, const double logsigma,
                          double *bins, const int count) {
  double s = 1. / (double)count;
  double z = s * 0.5;
  for (int i = 0; i < count; i++) {
    bins[i] = qlnorm(z, logmu, logsigma);
    z += s;
  }
}


x86 assembly (clang, -O0):
<lognormal_discretize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xed2(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeb9(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a2 <lognormal_discretize+0x92>
movsd  -0x30(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
call   1030 <qlnorm@plt>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1158 <lognormal_discretize+0x48>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lognormal_discretize>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %esi,%esi
jle    1198 <lognormal_discretize+0x88>
mov    %rdi,%r14
movaps %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
movsd  0xece(%rip),%xmm3
divsd  %xmm0,%xmm3
movsd  0xeca(%rip),%xmm0
movsd  %xmm3,0x8(%rsp)
mulsd  %xmm3,%xmm0
mov    %esi,%r15d
xor    %ebx,%ebx
movsd  %xmm1,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
nopl   0x0(%rax)
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
movaps %xmm2,%xmm1
movsd  0x18(%rsp),%xmm2
call   1030 <qlnorm@plt>
movsd  0x10(%rsp),%xmm2
movsd  %xmm0,(%r14,%rbx,8)
movsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <lognormal_discretize+0x50>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @lognormal_discretize(double %0, double %1, double* %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double* %2, double** %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = sitofp i32 %12 to double
%14 = fdiv double 1.000000e+00, %13
store double %14, double* %9
%15 = load double, double* %9
%16 = fmul double %15, 5.000000e-01
store double %16, double* %10
store i32 0, i32* %11
br label %17
17: ; preds = %33, %4
%18 = load i32, i32* %11
%19 = load i32, i32* %8
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load double, double* %10
%23 = load double, double* %5
%24 = load double, double* %6
%25 = call double @qlnorm(double %22, double %23, double %24)
%26 = load double*, double** %7
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
store double %25, double* %29
%30 = load double, double* %9
%31 = load double, double* %10
%32 = fadd double %31, %30
store double %32, double* %10
br label %33
33: ; preds = %21
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %17
36: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @lognormal_discretize(double %0, double %1, double* nocapture writeonly %2, i32 %3) {
%5 = sitofp i32 %3 to double
%6 = fdiv double 1.000000e+00, %5
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = fmul double %6, 5.000000e-01
%10 = zext i32 %3 to i64
br label %12
11: ; preds = %12, %4
ret void
12: ; preds = %8, %12
%13 = phi i64 [ 0, %8 ], [ %18, %12 ]
%14 = phi double [ %9, %8 ], [ %17, %12 ]
%15 = tail call double @qlnorm(double %14, double %0, double %1)
%16 = getelementptr inbounds double, double* %2, i64 %13
store double %15, double* %16
%17 = fadd double %6, %14
%18 = add nuw nsw i64 %13, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %11, label %12
}