#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 M_PI;
int abs(int);
double cos(int);
double plgndr(int, int, double);
double sin(int);
double sqrt(double);
void ylm(int l, int m, double theta, double phi, double *re, double *im) {
  int i;
  double coeff = 1.0;
  double plm, ylm;
  int sign = 1;
  if (m < 0.0) {
    sign *= -1;
  }
  m = abs(m);
  for (i = l - m; i > 1; i--) {
    coeff *= i;
  }
  for (i = l + m; i > 1; i--) {
    coeff /= i;
  }
  coeff *= (2.0 * l + 1.0) / 4.0 / M_PI;
  coeff = sqrt(coeff);
  plm = plgndr(l, m, cos(theta));
  ylm = coeff * plm;
  *re = ylm * cos(m * phi);
  *im = ylm * sin(m * phi);
  if (sign < 0) {
    *im *= -1;
    if (m % 2 == 1) {
      *re *= -1;
      *im *= -1;
    }
  }
}


x86 assembly (clang, -O0):
<ylm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movsd  0xe88(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x4c(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    119d <ylm+0x4d>
imul   $0xffffffff,-0x4c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jle    11d8 <ylm+0x88>
cvtsi2sdl -0x2c(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b1 <ylm+0x61>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jle    120c <ylm+0xbc>
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e1 <ylm+0x91>
cvtsi2sdl -0x4(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xde3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xddf(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    0x2db4(%rip),%rax
divsd  (%rax),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x64(%rbp)
cvttsd2si -0x10(%rbp),%edi
call   1050 <cos@plt>
mov    -0x68(%rbp),%edi
mov    -0x64(%rbp),%esi
call   1070 <plgndr@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0x0,-0x4c(%rbp)
jge    1347 <ylm+0x1f7>
mov    -0x28(%rbp),%rax
movsd  0xd12(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1342 <ylm+0x1f2>
mov    -0x20(%rbp),%rax
movsd  0xcea(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  0xcd6(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    1347 <ylm+0x1f7>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ylm>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
movsd  %xmm1,0x18(%rsp)
movapd %xmm0,%xmm2
mov    %esi,%r12d
mov    %edi,%ebp
mov    %esi,%ebx
neg    %ebx
cmovs  %esi,%ebx
mov    %edi,%eax
sub    %ebx,%eax
movsd  0xe8c(%rip),%xmm1
cmp    $0x2,%eax
jl     1195 <ylm+0x55>
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm0,%xmm1
lea    -0x1(%rax),%ecx
cmp    $0x2,%eax
mov    %ecx,%eax
ja     1180 <ylm+0x40>
lea    (%rbx,%rbp,1),%eax
cmp    $0x2,%eax
jl     11b5 <ylm+0x75>
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
lea    -0x1(%rax),%ecx
cmp    $0x2,%eax
mov    %ecx,%eax
ja     11a0 <ylm+0x60>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe38(%rip),%xmm0
mulsd  0xe38(%rip),%xmm0
mov    0x2e11(%rip),%rax
divsd  (%rax),%xmm0
mulsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ef <ylm+0xaf>
sqrtsd %xmm0,%xmm0
jmp    1200 <ylm+0xc0>
movsd  %xmm2,0x10(%rsp)
call   1050 <sqrt@plt>
movsd  0x10(%rsp),%xmm2
movsd  %xmm0,0x8(%rsp)
cvttsd2si %xmm2,%edi
call   1040 <cos@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <plgndr@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  0x18(%rsp),%xmm1
cvttsd2si %xmm1,%ebp
mov    %ebp,%edi
call   1040 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14)
mov    %ebp,%edi
call   1030 <sin@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r15)
test   %r12d,%r12d
jns    1294 <ylm+0x154>
xorpd  0xdaa(%rip),%xmm0
movlpd %xmm0,(%r15)
test   $0x1,%bl
je     1294 <ylm+0x154>
movsd  (%r14),%xmm0
movapd 0xd93(%rip),%xmm1
xorpd  %xmm1,%xmm0
movlpd %xmm0,(%r14)
movsd  (%r15),%xmm0
xorpd  %xmm1,%xmm0
movlpd %xmm0,(%r15)
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define void @ylm(i32 %0, i32 %1, double %2, double %3, double* %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store double %2, double* %9
store double %3, double* %10
store double* %4, double** %11
store double* %5, double** %12
store double 1.000000e+00, double* %14
store i32 1, i32* %17
%18 = load i32, i32* %8
%19 = sitofp i32 %18 to double
%20 = fcmp olt double %19, 0.000000e+00
br i1 %20, label %21, label %24
21: ; preds = %6
%22 = load i32, i32* %17
%23 = mul nsw i32 %22, -1
store i32 %23, i32* %17
br label %24
24: ; preds = %21, %6
%25 = load i32, i32* %8
%26 = call i32 @abs(i32 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = sub nsw i32 %27, %28
store i32 %29, i32* %13
br label %30
30: ; preds = %38, %24
%31 = load i32, i32* %13
%32 = icmp sgt i32 %31, 1
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i32, i32* %13
%35 = sitofp i32 %34 to double
%36 = load double, double* %14
%37 = fmul double %36, %35
store double %37, double* %14
br label %38
38: ; preds = %33
%39 = load i32, i32* %13
%40 = add nsw i32 %39, -1
store i32 %40, i32* %13
br label %30
41: ; preds = %30
%42 = load i32, i32* %7
%43 = load i32, i32* %8
%44 = add nsw i32 %42, %43
store i32 %44, i32* %13
br label %45
45: ; preds = %53, %41
%46 = load i32, i32* %13
%47 = icmp sgt i32 %46, 1
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load i32, i32* %13
%50 = sitofp i32 %49 to double
%51 = load double, double* %14
%52 = fdiv double %51, %50
store double %52, double* %14
br label %53
53: ; preds = %48
%54 = load i32, i32* %13
%55 = add nsw i32 %54, -1
store i32 %55, i32* %13
br label %45
56: ; preds = %45
%57 = load i32, i32* %7
%58 = sitofp i32 %57 to double
%59 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %58, double 1.000000e+00)
%60 = fdiv double %59, 4.000000e+00
%61 = load double, double* @M_PI
%62 = fdiv double %60, %61
%63 = load double, double* %14
%64 = fmul double %63, %62
store double %64, double* %14
%65 = load double, double* %14
%66 = call double @sqrt(double %65)
store double %66, double* %14
%67 = load i32, i32* %7
%68 = load i32, i32* %8
%69 = load double, double* %9
%70 = fptosi double %69 to i32
%71 = call double @cos(i32 %70)
%72 = call double @plgndr(i32 %67, i32 %68, double %71)
store double %72, double* %15
%73 = load double, double* %14
%74 = load double, double* %15
%75 = fmul double %73, %74
store double %75, double* %16
%76 = load double, double* %16
%77 = load i32, i32* %8
%78 = sitofp i32 %77 to double
%79 = load double, double* %10
%80 = fmul double %78, %79
%81 = fptosi double %80 to i32
%82 = call double @cos(i32 %81)
%83 = fmul double %76, %82
%84 = load double*, double** %11
store double %83, double* %84
%85 = load double, double* %16
%86 = load i32, i32* %8
%87 = sitofp i32 %86 to double
%88 = load double, double* %10
%89 = fmul double %87, %88
%90 = fptosi double %89 to i32
%91 = call double @sin(i32 %90)
%92 = fmul double %85, %91
%93 = load double*, double** %12
store double %92, double* %93
%94 = load i32, i32* %17
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %111
96: ; preds = %56
%97 = load double*, double** %12
%98 = load double, double* %97
%99 = fmul double %98, -1.000000e+00
store double %99, double* %97
%100 = load i32, i32* %8
%101 = srem i32 %100, 2
%102 = icmp eq i32 %101, 1
br i1 %102, label %103, label %110
103: ; preds = %96
%104 = load double*, double** %11
%105 = load double, double* %104
%106 = fmul double %105, -1.000000e+00
store double %106, double* %104
%107 = load double*, double** %12
%108 = load double, double* %107
%109 = fmul double %108, -1.000000e+00
store double %109, double* %107
br label %110
110: ; preds = %103, %96
br label %111
111: ; preds = %110, %56
ret void
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define void @ylm(i32 %0, i32 %1, double %2, double %3, double* nocapture %4, double* nocapture %5) {
%7 = icmp slt i32 %1, 0
%8 = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
%9 = sub nsw i32 %0, %8
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %18
11: ; preds = %6, %11
%12 = phi i32 [ %16, %11 ], [ %9, %6 ]
%13 = phi double [ %15, %11 ], [ 1.000000e+00, %6 ]
%14 = sitofp i32 %12 to double
%15 = fmul double %13, %14
%16 = add nsw i32 %12, -1
%17 = icmp ugt i32 %12, 2
br i1 %17, label %11, label %18
18: ; preds = %11, %6
%19 = phi double [ 1.000000e+00, %6 ], [ %15, %11 ]
%20 = add nsw i32 %8, %0
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %29
22: ; preds = %18, %22
%23 = phi i32 [ %27, %22 ], [ %20, %18 ]
%24 = phi double [ %26, %22 ], [ %19, %18 ]
%25 = sitofp i32 %23 to double
%26 = fdiv double %24, %25
%27 = add nsw i32 %23, -1
%28 = icmp ugt i32 %23, 2
br i1 %28, label %22, label %29
29: ; preds = %22, %18
%30 = phi double [ %19, %18 ], [ %26, %22 ]
%31 = sitofp i32 %0 to double
%32 = tail call double @llvm.fmuladd.f64(double %31, double 2.000000e+00, double 1.000000e+00)
%33 = fmul double %32, 2.500000e-01
%34 = load double, double* @M_PI
%35 = fdiv double %33, %34
%36 = fmul double %30, %35
%37 = tail call double @sqrt(double %36)
%38 = fptosi double %2 to i32
%39 = tail call double @cos(i32 %38)
%40 = tail call double @plgndr(i32 %0, i32 %8, double %39)
%41 = fmul double %37, %40
%42 = sitofp i32 %8 to double
%43 = fmul double %42, %3
%44 = fptosi double %43 to i32
%45 = tail call double @cos(i32 %44)
%46 = fmul double %41, %45
store double %46, double* %4
%47 = tail call double @sin(i32 %44)
%48 = fmul double %41, %47
store double %48, double* %5
br i1 %7, label %49, label %58
49: ; preds = %29
%50 = fneg double %48
store double %50, double* %5
%51 = and i32 %8, 1
%52 = icmp eq i32 %51, 0
br i1 %52, label %58, label %53
53: ; preds = %49
%54 = load double, double* %4
%55 = fneg double %54
store double %55, double* %4
%56 = load double, double* %5
%57 = fneg double %56
store double %57, double* %5
br label %58
58: ; preds = %49, %53, %29
ret void
}