#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 sqrt(int);
scalar_t__ util_malloc_(int);
double *sharp_Ylmgen_get_d1norm(int lmax) {
  const double pi = 3.141592653589793238462643383279502884197;
  double *res = ((double *)util_malloc_((lmax + 1) * sizeof(double)));
  for (int l = 0; l <= lmax; ++l)
    res[l] = (l < 1) ? 0. : 0.5 * sqrt(l * (l + 1.) * (2 * l + 1.) / (4 * pi));
  return res;
}


x86 assembly (clang, -O0):
<sharp_Ylmgen_get_d1norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  0xecd(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <util_malloc_@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11f6 <sharp_Ylmgen_get_d1norm+0xd6>
cmpl   $0x1,-0x1c(%rbp)
jge    1179 <sharp_Ylmgen_get_d1norm+0x59>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11d6 <sharp_Ylmgen_get_d1norm+0xb6>
cvtsi2sdl -0x1c(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xe8d(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe73(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe5b(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe3b(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <sharp_Ylmgen_get_d1norm+0x36>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sharp_Ylmgen_get_d1norm>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0x8(,%r15,8),%edi
call   1030 <util_malloc_@plt>
mov    %rax,%r14
test   %r15d,%r15d
js     11ad <sharp_Ylmgen_get_d1norm+0x8d>
movq   $0x0,(%r14)
je     11ad <sharp_Ylmgen_get_d1norm+0x8d>
add    $0x1,%r15d
mov    $0x1,%ebx
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movapd %xmm0,%xmm1
addsd  0xe8d(%rip),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm1,%xmm0
divsd  0xe7e(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
mulsd  0xe75(%rip),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
add    $0x2,%ebp
cmp    %rbx,%r15
jne    1160 <sharp_Ylmgen_get_d1norm+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @sharp_Ylmgen_get_d1norm(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double*
%5 = alloca i32
store i32 %0, i32* %2
store double 0x400921FB54442D18, double* %3
%6 = load i32, i32* %2
%7 = add nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = trunc i64 %9 to i32
%11 = call i64 @util_malloc_(i32 %10)
%12 = inttoptr i64 %11 to double*
store double* %12, double** %4
store i32 0, i32* %5
br label %13
13: ; preds = %43, %1
%14 = load i32, i32* %5
%15 = load i32, i32* %2
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %46
17: ; preds = %13
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %17
br label %37
21: ; preds = %17
%22 = load i32, i32* %5
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %5
%25 = sitofp i32 %24 to double
%26 = fadd double %25, 1.000000e+00
%27 = fmul double %23, %26
%28 = load i32, i32* %5
%29 = mul nsw i32 2, %28
%30 = sitofp i32 %29 to double
%31 = fadd double %30, 1.000000e+00
%32 = fmul double %27, %31
%33 = fdiv double %32, 0x402921FB54442D18
%34 = fptosi double %33 to i32
%35 = call double @sqrt(i32 %34)
%36 = fmul double 5.000000e-01, %35
br label %37
37: ; preds = %21, %20
%38 = phi double [ 0.000000e+00, %20 ], [ %36, %21 ]
%39 = load double*, double** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
store double %38, double* %42
br label %43
43: ; preds = %37
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %13
46: ; preds = %13
%47 = load double*, double** %4
ret double* %47
}

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